solanametaplex

solana. Mint nft with updateAuthority not equal to owner


it`s my first questions on stackoverflow :)

Id like to mint nft to my friend but еto reserve the right to update metadata. I use my publickey like updateAuthority for CreateMetadataAccountV3InstructionAccounts but response "Program log: Mint authority provided does not match the authority on the mint"

Thank you!!

  const ownerPubkey = new web3.PublicKey(owner);
  const payerPubkey = new web3.PublicKey(payer);
  const updatePubkey = new web3.PublicKey(update);

  const mint = web3.Keypair.generate();
  const instructions: web3.TransactionInstruction[] = [];
  const signers: web3.Keypair[] = [mint];

  const userTokenAccoutAddress = getTokenWallet(ownerPubkey, mint.publicKey);
  const metadataAccount = getMetadata(mint.publicKey);
  const editionAccount = getMasterEdition(mint.publicKey);

  instructions.push(
    web3.SystemProgram.createAccount({
      fromPubkey: ownerPubkey,
      newAccountPubkey: mint.publicKey,
      lamports: MINT_RENT,
      space: MintLayout.span,
      programId: TOKEN_PROGRAM_ID,
    })
  );

  instructions.push(
    createInitializeMintInstruction(
      mint.publicKey,
      0,
      updatePubkey,
      updatePubkey,
      TOKEN_PROGRAM_ID
    )
  );

  instructions.push(
    createAssociatedTokenAccountInstruction(
      payerPubkey,
      userTokenAccoutAddress,
      ownerPubkey,
      mint.publicKey
    )
  );

  const accounts: CreateMetadataAccountV3InstructionAccounts = {
    metadata: metadataAccount,
    mint: mint.publicKey,
    mintAuthority: ownerPubkey,
    payer: payerPubkey,
    updateAuthority: updatePubkey,
  };

  const args: CreateMetadataAccountV3InstructionArgs = {
    createMetadataAccountArgsV3: {
      data,
      isMutable: true,
      collectionDetails: null,
    },
  };

  instructions.push(createCreateMetadataAccountV3Instruction(accounts, args));

  instructions.push(
    createMintToInstruction(
      mint.publicKey,
      userTokenAccoutAddress,
      ownerPubkey,
      1
    )
  );

  instructions.push(
    createCreateMasterEditionV3Instruction(
      {
        edition: editionAccount,
        ...accounts,
      },
      { createMasterEditionArgs: { maxSupply: 0 } }
    )
  );

I use my publickey like updateAuthority for CreateMetadataAccountV3InstructionAccounts but response "Program log: Mint authority provided does not match the authority on the mint"


Solution

  • When you create the metadata account and mint tokens, you're specifying the mint authority as ownerPubkey, when you previously specified updatePubkey. You should change them to:

      const accounts: CreateMetadataAccountV3InstructionAccounts = {
        metadata: metadataAccount,
        mint: mint.publicKey,
        mintAuthority: updatePubkey,
        payer: payerPubkey,
        updateAuthority: updatePubkey,
      };
    

    and

      instructions.push(
        createMintToInstruction(
          mint.publicKey,
          userTokenAccoutAddress,
          updatePubkey,
          1
        )
      );