0

I'm trying to use metaplex's mpl token metadata to get the burn instruction.

Here is my code :

import { burnNft } from '@metaplex-foundation/mpl-token-metadata'
...
var umi = createUmi(SOLANA_CLUSTER)

  var accounts = {
    collectionMetadata: getPdaMetadata(collectionAddress),
    masterEditionAccount: getPdaEdition(mintAddress),
    editionAccount: getPdaEdition(mintAddress),
    metadata: getPdaMetadata(mintAddress),
    mint: mintAddress,
    owner: owner,
    splTokenProgram: TOKEN_PROGRAM_ID,
    tokenAccount: tokenAccount
  }

  var transactionBuilder = await burnNft(umi, accounts)

  var instruction = transactionBuilder.getInstructions()[0];

let transaction = new Transaction();
transaction.add(instruction);
...

When i try to send the transaction, i have the following error :

BurnArtwork.vue:85 WalletSendTransactionError: x.pubkey.toBase58 is not a function

If i console log the transaction object, i can see that there is no signature in the signatures array (not an empty signature, i mean the array is really empty), so it might be linked.

What am i doing wrong ?

I know that there is metaplex/js with .delete() method, but i can't figure out how to use it with vue wallet adapter (the .use(walletAdapterIdentity(wallet)) part, i don't know what is "wallet" / how to get it).

0

2 Answers 2

1

Error Message

The error message states that x.pubkey.toBase58 is not a function, meaning that x doesn't have a pubkey property, or the pubkey property on x doesn't have a toBase58() method. This suggests that you have a mismatch between the expected type of x and what's actually being passed.

Without the rest of the code, it's hard to diagnose the exact issue that you're running into. I'd recommend logging the objects and their types, wherever relevant, to get a better understanding of what they actually contain. This can be achieved with something like:

// Log the type and value of x
console.log(typeof x, x);

// Log the type and value of x.pubkey
console.log(typeof x.pubkey, x.pubkey); 

You'll want to make sure that all the public keys in your code (mintAddress, owner, tokenAccount, etc.) are instances of Solana's PublicKey class.

Empty signatures Array

The signatures array being empty could imply that the transaction is not being signed properly. You could use the sendAndConfirmTransaction function from @solana/web3.js to sign, send, and confirm the transaction all in one go. If not, you'll need to make sure first that the transaction is signed by the appropriate key pair(s). Once you have signed the transaction, then the signatures array will be populated and you can send the transaction. On Solana, transactions must be signed before they are sent off

Delete Method

The Metaplex Token Metadata documentation has a section on burning NFTs, which can be found here. They give the following example of how to use the SDK to burn an asset on Token Metadata:

import { burnV1 } from '@metaplex-foundation/mpl-token-metadata'

await burnV1(umi, {
  mint,
  authority: owner,
  tokenOwner: owner.publicKey,
  tokenStandard: TokenStandard.NonFungible,
}).sendAndConfirm(umi)

This example is helpful as they abstract away the process of constructing the burn instruction manually and setting up the accounts. sendAndConfirm is also chained to the burnV1 method, which handles the transaction signing and sending in one go. If you're keen on building the transaction yourself, Metaplex has a createBurnNftInstruction, and the set up is almost identical to your current code except you're using createBurnNftInstruction instead of burnNft. The documentation for the createBurnNftInstruction can be found here

Update [09-13-2023]

Ah! After looking at your code again it looks like you are trying to import burnNft from @metaplex-foundation/mpl-token-metadata but Metaplex's burnNft.ts doesn't have a burnNft export. Instead, BurnNftStruct, BurnNftInstructionAccounts, burnNftInstructionDiscriminator, and createBurnNftInstruction are being exported from that file. This might be able to explain as to why you've been experiencing some weird functionality.

If you want to continue on with how you're currently building the transaction, then I'd suggest you import createBurnNftInstruction instead. Otherwise, Metaplex's new documentation suggests using burnV1

I hope this was helpful!

3
  • 1) error message => i don't know what is "x", i don't have it in my code. I did try to log all accounts involved, and they are all web3 public keys object 2) as i said, the problem is when i try to sign the transaction, it looks like the instruction doesn't require a signature, but it should. The signatures array is (should be!) populated before signing the transaction (when constructing the instruction). Onlye the signature key in the object is null, and replaced when you actually sign the transaction. In my case it's not populated at all
    – Effe2
    Sep 13, 2023 at 8:04
  • 3) do you know the difference between burnNft and burnV1 ? (i can't get the difference with the docs..., they look very similar). Yes i tried with createBurnNftInstruction, but this method is not exported in mpl token metadata, so it is undefined and can't use it to create my instruction (this was my first atempt, because it was done like this in older versions). I actually solved my problem by fully writting the instruction by myself (with discriminator, etc), but i will try the burnV1 as soon as i can, and will let you know if it did solved the problem !
    – Effe2
    Sep 13, 2023 at 8:09
  • @Effe2 let me know if you're able to figure it out! I've added an update to my original answer which should be helpful :)
    – 0xIchigo
    Sep 13, 2023 at 17:28
0

as @0xIchigo above suggested, Metaplex's documentation uses burnV1. Mixing and matching code that worked in the past will most likely result in an error. For example using solana web3.js PublicKey type will result in an error as most definition require you to use umi's publickey interface.

Here is the code that worked for me

const mint = publicKey("Eftb5zJLkXtCL3CwfyELXw6nVRM9fpPNH4tdeeFat4Xg");
const burnNft = async () => {
    await burnV1(umi, {
        mint, // public key
        authority: umi.identity, //signer
        tokenOwner: umi.identity.publicKey, // public key
        tokenStandard: TokenStandard.NonFungible, // token standard
    }).sendAndConfirm(umi)
}

burnNft()
    .then()
    .catch(err => console.error(err))

Also, make sure to use the mplTokenMetadata() plugin or you'll end with the ProgramNotRecognizedError: The provided program name [splAssociatedToken] is not recognized in the [devnet] cluster.

1
  • 1
    will take a look as soon as i have more time and let you know, thank you both
    – Effe2
    Sep 17, 2023 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.