Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

136
Vistas
Candy Machine V2 - Trying to get all the nfts created by one candy machine

I am trying to figure out all the nfts that were created by one candy machine. I am so confused with the v2. Here is what I have done so far.

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;
  }

As per metaplex discord chat earlier. I need to get first creator that with this function

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

in order to fetch the hashTables as folllow

  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;
  };

The problem is that my function getProgramAccounts is not returning anything.

Can anyone tell me what I am doing wrong?

Thank you

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

deriveCandyMachineV2ProgramAddress should return an array with 2 values so to get creator key you need access first element: const [creatorKey] = await deriveCandyMachineV2ProgramAddress(hash) and this return a publicKey interface so just change bytes: creatorKey to bytes: creatorKey.toBase58()

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda