简体   繁体   English

创建 metaplex 元数据帐户时出现索引超出范围错误

[英]Getting index out of range error when creating metaplex metadata account

Why am I getting the following error when trying to create a metadata account using createCreateMetadataAccountV2Instruction from the @metaplex-foundation/mpl-token-metadata library?为什么在尝试使用 @ createCreateMetadataAccountV2Instruction @metaplex-foundation/mpl-token-metadata库中的 createCreateMetadataAccountV2Instruction 创建元数据帐户时出现以下错误?

SendTransactionError: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: Program failed to complete
    at Connection.sendEncodedTransaction (C:\xampp\htdocs\sol-tools\node_modules\@solana\web3.js\src\connection.ts:4464:13) 
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Connection.sendRawTransaction (C:\xampp\htdocs\sol-tools\node_modules\@solana\web3.js\src\connection.ts:4423:20)
    at async Connection.sendTransaction (C:\xampp\htdocs\sol-tools\node_modules\@solana\web3.js\src\connection.ts:4411:12)  
    at async sendAndConfirmTransaction (C:\xampp\htdocs\sol-tools\node_modules\@solana\web3.js\src\util\send-and-confirm-transaction.ts:31:21)
    at async addMetadataToToken (C:\xampp\htdocs\sol-tools\src\lib\metadata.ts:86:16)
    at async Command.<anonymous> (C:\xampp\htdocs\sol-tools\src\cli.ts:48:7) {
  logs: [
    'Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s invoke [1]',
    'Program log: Instruction: Create Metadata Accounts v2',
    "Program log: panicked at 'range end index 36 out of range for slice of length 0', program/src/utils.rs:231:27",        
    'Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s consumed 6223 of 1400000 compute units',
    'Program failed to complete: BPF program panicked',
    'Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s failed: Program failed to complete'
  ]
}

Here's my code:这是我的代码:

import {
  createCreateMetadataAccountV2Instruction,
  PROGRAM_ID,
} from '@metaplex-foundation/mpl-token-metadata'
import {
  Connection,
  Keypair,
  PublicKey,
  sendAndConfirmTransaction,
  Transaction,
} from '@solana/web3.js'

export const addMetadataToToken = async (
  connection: Connection,
  tokenMint: PublicKey,
  tokenOwner: Keypair,
  name: string,
  symbol: string,
  arweaveLink: string
) => {
  const seed1 = Buffer.from('metadata', 'utf8')
  const seed2 = PROGRAM_ID.toBuffer()
  const seed3 = tokenMint.toBuffer()
  const [metadataPDA, _bump] = PublicKey.findProgramAddressSync(
    [seed1, seed2, seed3],
    PROGRAM_ID
  )
  const accounts = {
    metadata: metadataPDA,
    mint: tokenMint,
    mintAuthority: tokenOwner.publicKey,
    payer: tokenOwner.publicKey,
    updateAuthority: tokenOwner.publicKey,
  }
  const dataV2 = {
    name,
    symbol,
    uri: arweaveLink,
    // we don't need these
    sellerFeeBasisPoints: 0,
    creators: null,
    collection: null,
    uses: null,
  }
  const args = {
    createMetadataAccountArgsV2: {
      data: dataV2,
      isMutable: true,
    },
  }
  const ix = createCreateMetadataAccountV2Instruction(accounts, args)
  const tx = new Transaction()
  tx.add(ix)
  const txid = await sendAndConfirmTransaction(connection, tx, [tokenOwner])
  console.log(txid)
}

Turns out I was on trying to create metadata for a token on devnet, but was using a mainnet-beta rpc endpoint for the Connection class.原来我是在尝试为 devnet 上的令牌创建元数据,但正在为Connection类使用 mainnet-beta rpc 端点。 Thus the token I was trying to create metadata for didn't exist.因此,我试图为其创建元数据的令牌不存在。

This is a really Common Error Message that occurs when there is some issue with what you are passing to the program.这是一个非常常见的错误消息,当您传递给程序的内容出现问题时会发生这种错误消息。 So make sure everything that you are input to the program is correct.因此,请确保您输入到程序中的所有内容都是正确的。 In 90% of the cases, it gets resolved when checking the inputs correctly.在 90% 的情况下,在正确检查输入时它会得到解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM