3

I'm getting "SendTransactionError: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: Program failed to complete" Where did i go wrong?

const tokenMetadata = {
    name: name,
    symbol: symbol,
    uri: uri,
    sellerFeeBasisPoints: 0,
    creators: null,
    collection: null,
    uses: null,
  } as DataV2

  // transaction to create metadata account
  const transaction = new web3.Transaction().add(
    createCreateMetadataAccountV3Instruction(
      {
        metadata: metadataPDA,
        mint: mint,
        mintAuthority: user.publicKey,
        payer: user.publicKey,
        updateAuthority: user.publicKey,
      },
      {
        createMetadataAccountArgsV3: {
          data: tokenMetadata,
          isMutable: true,
          collectionDetails: null
        },
      }
    )    

1 Answer 1

3

Few things to check (Usually better to turn off preflight check to see the actual error from the block explorer)

  1. Check the symbol isn't too long
  2. Check the transaction is not too large (long URLs cause this)
  3. Ensure MetadataPDA is correct
  4. Ensure you set recentBlockhash & payer params on the transaction

Data structure all looks correct from the code you have posted

Here is a full example of creating a NFT:

import {web3} from "@project-serum/anchor";
import {createCreateMasterEditionV3Instruction, createCreateMetadataAccountV3Instruction, PROGRAM_ID} from "@metaplex-foundation/mpl-token-metadata";
import {
    createAssociatedTokenAccountInstruction,
    createInitializeMintInstruction,
    createMintToInstruction,
    getAssociatedTokenAddressSync,
    MINT_SIZE,
    TOKEN_PROGRAM_ID
} from "@solana/spl-token";

async function getCreateNFTTransaction(owner: web3.PublicKey, connection: web3.Connection): web3.Transaction {
    const nftMint = web3.Keypair.generate()
    const tokenMint = nftMint.publicKey
    const [metadataPDA] = web3.PublicKey.findProgramAddressSync([Buffer.from("metadata"), PROGRAM_ID.toBuffer(), tokenMint.toBuffer()], PROGRAM_ID)

    const mintLamports = await connection.getMinimumBalanceForRentExemption(MINT_SIZE);

    const ata = getAssociatedTokenAddressSync(tokenMint, owner, false, TOKEN_PROGRAM_ID)


    const [nftMasterEdition] = web3.PublicKey.findProgramAddressSync([Buffer.from("metadata"), PROGRAM_ID.toBuffer(), nftMint.publicKey.toBuffer(), Buffer.from("edition")],
        PROGRAM_ID)

    const ON_CHAIN_METADATA = {
        name: "{NAME}",
        symbol: "{SYMBOL}",
        uri: "{URI}",
        sellerFeeBasisPoints: 0,
        uses: null,
        creators: [],
        collection: null,
    };

    const txn = new web3.Transaction().add(
        web3.SystemProgram.createAccount({
            fromPubkey: owner,
            newAccountPubkey: tokenMint,
            space: MINT_SIZE,
            lamports: mintLamports,
            programId: TOKEN_PROGRAM_ID,
        }),
    );

    txn.add(createInitializeMintInstruction(tokenMint, 0, owner, owner, TOKEN_PROGRAM_ID),
        createCreateMetadataAccountV3Instruction({
            metadata: metadataPDA,
            mint: tokenMint,
            mintAuthority: owner,
            payer: owner,
            updateAuthority: owner,
        }, {
            createMetadataAccountArgsV3:
                {
                    data: ON_CHAIN_METADATA,
                    isMutable: false,
                    collectionDetails: null
                }
        }, PROGRAM_ID),
        createAssociatedTokenAccountInstruction(owner, ata, owner, tokenMint, TOKEN_PROGRAM_ID),
    )

    txn.add(createMintToInstruction(tokenMint, ata, owner, 1n, [], TOKEN_PROGRAM_ID))


    //Used to create a master collection
    // txn.add(createSetAndVerifyCollectionInstruction({
    //  metadata: metadataPDA,
    //  collectionAuthority: owner,
    //  payer: owner,
    //  updateAuthority: owner,
    //  collectionMint: collectionMint,
    //  collection: collectionMetadata,
    //  collectionMasterEditionAccount: collectionMasterEdition,
    //  collectionAuthorityRecord: collectionAuthority,
    // }))


    txn.add(createCreateMasterEditionV3Instruction({
        edition: nftMasterEdition,
        mint: nftMint.publicKey,
        updateAuthority: owner,
        mintAuthority: owner,
        payer: owner,
        metadata: metadataPDA,
        tokenProgram: TOKEN_PROGRAM_ID,
    }, {createMasterEditionArgs: {maxSupply: 0}}))

    const bhash = await connection.getLatestBlockhash("confirmed")
    txn.feePayer = owner
    txn.recentBlockhash = bhash.blockhash
    return txn
}
5
  • I added a try catch statement and debugged the code to find out the issue is with this code: try { // send transaction const transactionSignature = await web3.sendAndConfirmTransaction( connection, transaction, [user] ); console.log( `Create Metadata Account: https://explorer.solana.com/tx/${transactionSignature}?cluster=devnet` ) } catch (error) { console.log("Error: ", error); } @Cloakd
    – Aru Arshad
    Commented Jul 26, 2023 at 11:21
  • The error that I'm getting: Error: SendTransactionError: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: Program failed to complete
    – Aru Arshad
    Commented Jul 26, 2023 at 11:27
  • Have you created the mint & metadata PDA?
    – Cloakd
    Commented Jul 26, 2023 at 12:48
  • I figured it out myself. I used a different method. Thanks a lot for your help though. Cheers
    – Aru Arshad
    Commented Jul 27, 2023 at 2:18
  • For future reference, Program failed to complete means that the on-chain program panicked / crashed during execution. This could happen for a few reasons: a bug in the program, running out of VM compute units, etc
    – Jon C
    Commented Jul 27, 2023 at 13:19

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.