alchemyplatform/alchemy-web3

getNFTs with contractAddresses filter does not work

outdoteth opened this issue · 3 comments

It fails to filter out the other addresses. For example on Ropsten:

const nfts = await alchemy.getNfts({
  owner: "0xc9a6EC4aE16AD5A1B75Cf8f111FBD69eC3788774",
  contractAddresses: ["0x18e132bE028b77e6bb9bE98620bB335005077907"],
});
console.log("nfts", nfts);

Response includes addresses other than "0x18e132bE028b77e6bb9bE98620bB335005077907":
Screenshot 2022-02-06 at 14 24 32

On closer inspection of the network tab, the library is sending the following params:

/v1/getNFTs/?owner=0xc9a6EC4aE16AD5A1B75Cf8f111FBD69eC3788774&contractAddresses=0x18e132bE028b77e6bb9bE98620bB335005077907

But this differs from the example in the documentation which says it should be:

/v1/getNFTs/?owner=0xc9a6EC4aE16AD5A1B75Cf8f111FBD69eC3788774&contractAddresses[]=0x18e132bE028b77e6bb9bE98620bB335005077907

(Note the additional [] after contractAddresses).

After using the format in the documentation, I get the expected result:

Screenshot 2022-02-06 at 14 27 32

Hmm, so I haven't confirmed this but I suspect this issue was introduced in this PR:
#82

See this issue here: medialize/URI.js#3

If I change it to be this then it works:

const nfts = await alchemy.getNfts({
  owner: "0xc9a6EC4aE16AD5A1B75Cf8f111FBD69eC3788774",
  "contractAddresses[]": ["0x18e132bE028b77e6bb9bE98620bB335005077907"],
});
console.log("nfts", nfts);

Screenshot 2022-02-06 at 20 12 30

Hi there, thank you for the report! I am working on a fix.

Fix published in 1.2.2. Thank you very much for the report and sorry for the trouble!