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
await
the connection args as well. - silencedogood