diff --git a/components/SendNft.tsx b/components/SendNft.tsx index a0e15abad..eaea6b4c6 100644 --- a/components/SendNft.tsx +++ b/components/SendNft.tsx @@ -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 diff --git a/hooks/queries/digitalAssets.ts b/hooks/queries/digitalAssets.ts index fcbdcab2c..57a302c5a 100644 --- a/hooks/queries/digitalAssets.ts +++ b/hooks/queries/digitalAssets.ts @@ -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. diff --git a/utils/metaplex.ts b/utils/metaplex.ts index 0ad1667df..c77258b02 100644 --- a/utils/metaplex.ts +++ b/utils/metaplex.ts @@ -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 ( @@ -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 + } }