js
js copied to clipboard
Candy Machine findMintedNFTs returning Thousands of random NFTs
Trying to implement candyMachines().findMintedNFTs (or nfts().findAllByCreator ) but the results are more than 100k of random NFTs. I am using the candy machine Id for Okay bears as testing point:
const metaplex = Metaplex.make(connection)
.use(keypairIdentity(wallet))
.use(bundlrStorage());
const getMintAddresses = async (firstCreatorAddress) => {
const nfts = await metaplex
.candyMachines()
.findMintedNfts({ creator: firstCreatorAddress, version: 1 })
.run();
console.log(nfts);
};
var candyMachineId = new web3.PublicKey(
"3xVDoLaecZwXXtN59o6T3Gfxwjcgf8Hc9RfoqBn995P9"
);
getMintAddresses(candyMachineId);
Anything else that should be added here? Any filter or additional parameter that might be missing?
You're not alone. However, I'm getting the same results with FindAllByCreator()
, without Candy Machine. Returns 157k items on Mainnet. About 1/4 that on Devnet.
@neilryanh it's like if the parameter was ignored then. Will do some digging to check if the parameter must be passed differently but based on the docs this code should work correctly.
@camilomv17 I also tried to use findAllByUpdateAuthority()
, which I found in the module operations (not seeing this particular method in Docs) . Same result.
Also, findAllByCreator()
does have optional params and utilizing creator postion:1 is the same.
I have simulated the RPC call made by this method findMintedNFTs()
and I noticed that add a filter not needed:
{
"memcmp": { //<--- this not needed if remove this I get the results also for v1 and v2
"offset": 0,
"bytes": "5"
}
},
{
"memcmp": {
"offset": 326,
"bytes": "3xVDoLaecZwXXtN59o6T3Gfxwjcgf8Hc9RfoqBn995P9"
}
}
]```
Nice find @cicoph, looks like we will have to do a manual RPC call until this is fixed by metaplex. Will test and confirm if works on my side.
Hi there 👋
Thanks for raising this.
I'm confused about the proposed solution here.
Are we saying that the filter on the discriminator is the problem and should be removed?
I'm struggling to understand why removing a filter would narrow down the amount of NFTs returned but maybe I got that wrong.
Yes, I can't use the findMintedNFTs methods because it add a discriminator not needed.
...
{
"memcmp": { //<--- this not needed if remove this I get the results also for v1 and v2
"offset": 0,
"bytes": "5"
}
},
...```
Am I happy to remove the discriminator filter if this creates another issue but I am confused as to why this fixes the problem described as "the results are more than 100k of random NFTs".
Ah ok. I just tell him to try getProgramAccounts without the discriminator :) to try to fix.
FWIW I had the same issue - but mine led to a timeout rather than 100k random NFTs. Removing the line this.whereKey(Key.MetadataV1);
from the gpa builder did the trick to get back just the right NFTs.
https://github.com/metaplex-foundation/js/blob/c3985c74eb0c9cf9cf9b9423eb73b0665ce22d80/packages/js/src/plugins/nftModule/gpaBuilders.ts#L31
Am I happy to remove the discriminator filter if this creates another issue but I am confused as to why this fixes the problem described as "the results are more than 100k of random NFTs".
@lorisleiva I suspect some provider is using a bad custom implementation of getProgramAccounts
where they assume/allow only one memcmp filter.
The fix might be to reverse the order of the filters so the critical one appears first.