【问题标题】:Candy Machine V2 - Trying to get all the nfts created by one candy machineCandy Machine V2 - 试图获得一台糖果机创建的所有 nfts
【发布时间】:2022-01-07 14:23:36
【问题描述】:

我正在尝试找出由一台糖果机创建的所有 nft。我对v2很困惑。这是我到目前为止所做的。

async function getProgramAccounts(
    connection,
    programId,
    configOrCommitment,
  ) {
    const extra = {};
    let commitment;
    //let encoding;
  
    if (configOrCommitment) {
      if (typeof configOrCommitment === 'string') {
        commitment = configOrCommitment;
      } else {
        commitment = configOrCommitment.commitment;
        //encoding = configOrCommitment.encoding;
  
        if (configOrCommitment.dataSlice) {
          extra.dataSlice = configOrCommitment.dataSlice;
        }
  
        if (configOrCommitment.filters) {
          extra.filters = configOrCommitment.filters;
        }
      }
    }
    const args = connection._buildArgs([programId], commitment, 'base64', extra);
    const unsafeRes = await (connection)._rpcRequest(
      'getProgramAccounts',
      args,
    );
  
    return unsafeRes.result;
  }

根据之前的 metaplex discord chat。我需要使用此功能获得第一个创建者

  const deriveCandyMachineV2ProgramAddress = async (
    candyMachineId,
  ) => {
    const candyMachineID = new PublicKey(candyMachineId);
    return await PublicKey.findProgramAddress(
      [Buffer.from('candy_machine'), candyMachineID.toBuffer()],
      candyMachineProgram,
    );
  };
  

为了获取哈希表如下

  const fetchHashTable = async (hash, metadataEnabled) => {
    const connection = new web3.Connection(
      process.env.REACT_APP_SOLANA_RPC_HOST
    );
    const creatorKey = await deriveCandyMachineV2ProgramAddress(hash)
  
    const metadataAccounts = await getProgramAccounts(
      connection,
      {
        filters: [
          {
            memcmp: {
              offset:
                1 +
                32 +
                32 +
                4 +
                MAX_NAME_LENGTH +
                4 +
                MAX_URI_LENGTH +
                4 +
                MAX_SYMBOL_LENGTH +
                2 +
                1 +
                4 +
                0 * MAX_CREATOR_LEN,
              bytes: creatorKey,
            },
          },
        ],
      }
    );

    const mintHashes = [];

    for (let index = 0; index < metadataAccounts.length; index++) {
      const account = metadataAccounts[index];
      const accountInfo = await connection.getParsedAccountInfo(account.pubkey);
      const metadata = new Metadata(hash.toString(), accountInfo.value);
      if (metadataEnabled) mintHashes.push(metadata.data);
      else mintHashes.push(metadata.data.mint);
    }
    console.log(mintHashes, 'minthashes')
    return mintHashes;
  };

问题是我的函数getProgramAccounts 没有返回任何内容。

谁能告诉我我做错了什么?

谢谢

【问题讨论】:

  • 也许您还需要await 连接参数。
  • 谢谢。我从 metaplex github 得到了这个函数,我不认为 await 在那里,但我添加了它以防万一,但它仍然没有返回任何东西。

标签: javascript solana metaplex


【解决方案1】:

deriveCandyMachineV2ProgramAddress 应该返回一个包含 2 个值的数组,因此要获得创建者密钥,您需要访问第一个元素:const [creatorKey] = await deriveCandyMachineV2ProgramAddress(hash) ,这会返回一个 publicKey 接口,因此只需将 bytes: creatorKey 更改为 bytes: creatorKey.toBase58()

【讨论】:

    猜你喜欢
    • 2022-10-19
    • 2022-06-14
    • 2022-07-05
    • 1970-01-01
    • 2022-06-11
    • 1970-01-01
    • 1970-01-01
    • 2022-06-26
    • 2022-07-22
    相关资源
    最近更新 更多