You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Solana铸造NFT时updateAuthority与owner不同报错求助

问题:铸造NFT时设置元数据更新权限报错

我想给朋友铸造NFT,但保留元数据的更新权限。我将自己的公钥作为CreateMetadataAccountV3InstructionAccounts的updateAuthority,但收到报错信息:

"Program log: Mint authority provided does not match the authority on the mint"

相关代码如下:

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 } }
  )
);
解决方案

报错核心原因是初始化mint账户时设置的铸币权限,和后续元数据创建、铸币操作中传入的铸币权限不一致:

  1. 你在createInitializeMintInstruction里把铸币权限设成了自己的公钥updatePubkey,但后续CreateMetadataAccountV3和createMintToInstruction里用的是朋友的公钥ownerPubkey,两者不匹配触发了权限校验错误。

要实现「给朋友铸造NFT,自己保留元数据更新权限」的需求,正确的权限分配应该是:

  • 铸币权限交给朋友(ownerPubkey),确保他能完成铸币操作;
  • 元数据更新权限保留给自己(updatePubkey),后续可修改元数据;
  • 冻结权限可按需设置,这里和铸币权限保持一致即可。

修改后的关键代码如下:

1. 修正mint初始化指令

instructions.push(
  createInitializeMintInstruction(
    mint.publicKey,
    0,
    ownerPubkey, // 铸币权限设为朋友的公钥
    ownerPubkey, // 冻结权限同步设为朋友的公钥,按需调整
    TOKEN_PROGRAM_ID
  )
);

2. 保持元数据更新权限不变

CreateMetadataAccountV3InstructionAccounts中的updateAuthority依然用你的公钥,这部分无需修改:

const accounts: CreateMetadataAccountV3InstructionAccounts = {
  metadata: metadataAccount,
  mint: mint.publicKey,
  mintAuthority: ownerPubkey, // 和初始化的铸币权限保持一致
  payer: payerPubkey,
  updateAuthority: updatePubkey, // 你的公钥,保留元数据更新权限
};

3. 铸币指令权限同步

createMintToInstruction中的铸币权限也和初始化保持一致:

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

修改后,铸币权限在全流程中保持一致,即可解决报错,同时你依然拥有元数据的更新权限。

内容的提问来源于stack exchange,提问作者keker

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 07:10:27