3

我试图找出由一台糖果机创建的所有 nfts。我对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没有返回任何东西。

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

谢谢

4

1 回答 1

0

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

于 2022-01-30T04:14:27.567 回答