Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/SendNft.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const SendNft = ({
serializedInstruction: serializeInstructionToBase64(transferIx),
isValid: true,
prerequisiteInstructions:
destinationAtaQueried === null
destinationAtaQueried === null && nft.interface !== 'MplCoreAsset'
? [
Token.createAssociatedTokenAccountInstruction(
ASSOCIATED_TOKEN_PROGRAM_ID, // always ASSOCIATED_TOKEN_PROGRAM_ID
Expand Down
1 change: 1 addition & 0 deletions hooks/queries/digitalAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export type DasNftObject = {
verified: boolean
}[]
id: string
interface?: string
}

/*** Here is an example item from the DAS Api, since it's not typed and the docs dont give the full schema.
Expand Down
62 changes: 42 additions & 20 deletions utils/metaplex.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { fetchNFTbyMint } from '@hooks/queries/nft'
import { Metaplex } from '@metaplex-foundation/js'
import { TokenStandard } from '@metaplex-foundation/mpl-token-metadata'
import { Connection, PublicKey } from '@solana/web3.js'

export const createIx_transferNft = async (
Expand All @@ -21,27 +22,48 @@ export const createIx_transferNft = async (
//metaplex.identity = () => ({ publicKey: fromOwner } as any) // you need to do this to set payer and authority. I love OOP!!
// except the payer might not be the same person. great!

const nft = await fetchNFTbyMint(connection, mint)
if (!nft.result) throw 'failed to fetch nft'
try {
const nft = await fetchNFTbyMint(connection, mint)
if (!nft.result) throw 'failed to fetch nft'

const tokenStandard = nft.result.tokenStandard
const ruleSet = nft.result.programmableConfig?.ruleSet
const tokenStandard = nft.result.tokenStandard
const ruleSet = nft.result.programmableConfig?.ruleSet

const ix = metaplex
.nfts()
.builders()
.transfer({
nftOrSft: {
address: mint,
tokenStandard,
},
authorizationDetails: ruleSet ? { rules: ruleSet } : undefined,
toOwner,
fromOwner,
})
.getInstructions()[0]
const ix = metaplex
.nfts()
.builders()
.transfer({
nftOrSft: {
address: mint,
tokenStandard,
},
authorizationDetails: ruleSet ? { rules: ruleSet } : undefined,
toOwner,
fromOwner,
})
.getInstructions()[0]

ix.keys[9].pubkey = authority
ix.keys[10].pubkey = payer
return ix
ix.keys[9].pubkey = authority
ix.keys[10].pubkey = payer
return ix
} catch {
const ix = metaplex
.nfts()
.builders()
.transfer({
nftOrSft: {
address: mint,
tokenStandard: TokenStandard.NonFungible,
},
authorizationDetails: undefined,
toOwner,
fromOwner,
})
.getInstructions()[0]

ix.keys[9].pubkey = authority
ix.keys[10].pubkey = payer

return ix
}
}
Loading