js icon indicating copy to clipboard operation
js copied to clipboard

Candy Machine findMintedNFTs returning Thousands of random NFTs

Open camilomv17 opened this issue 2 years ago • 11 comments

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?

camilomv17 avatar Sep 05 '22 21:09 camilomv17

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 avatar Sep 10 '22 00:09 neilryanh

@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 avatar Sep 10 '22 10:09 camilomv17

@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.

neilryanh avatar Sep 10 '22 13:09 neilryanh

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"
    }
  }
]```

cicoph avatar Sep 19 '22 22:09 cicoph

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.

camilomv17 avatar Sep 20 '22 15:09 camilomv17

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.

lorisleiva avatar Sep 30 '22 13:09 lorisleiva

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"
    }
  },
...```

cicoph avatar Sep 30 '22 13:09 cicoph

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 avatar Sep 30 '22 13:09 lorisleiva

Ah ok. I just tell him to try getProgramAccounts without the discriminator :) to try to fix.

cicoph avatar Sep 30 '22 13:09 cicoph

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

cosimo-rip avatar Oct 03 '22 16:10 cosimo-rip

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.

KartikSoneji avatar Nov 17 '22 05:11 KartikSoneji