[SOLVED] Rarity Ranking NFT on Polygon

Iā€™m working on the Rarity Ranking tutorial, and I noticed the default chain is eth, but my collection is on Polygon.

Ran cloud function getAllTokenIds for user undefined with:
Input: {ā€œaddressā€:ā€œ0x51790d397e3cC5F418635796e75C8B58EA113f3Dā€,ā€œchainā€:ā€œethā€}
Result: {ā€œtotalā€:0,ā€œpageā€:0,ā€œpage_sizeā€:500,ā€œcursorā€:"",ā€œresultā€:[]}

Iā€™ve searched the repo in VSCode and couldnā€™t figure out where I might be able to set the chain to Polygon.

Iā€™m not a programmer, so I am struggling with basic concepts. I have no idea how to work with Cloud Functions, which was a suggested solution.

I think the Rarity Generator would work as intended for me, if I could understand how to make this modification.

TYVM

Sure,

Let me help you out.

You can find all the API end points here:

You can see the chains here -

1 Like

I donā€™t understand how this will change the Input being sent when I use ā€œnode main.jsā€. If you could help me understand I would be very grateful . . .

Can u share the Github path where u are referring to the code?

Shockingly, I managed to make it work on Polygon. It was purely guesswork, feel free to correct me, as I am not a coder by any stretch. I changed 3 things in main.js, adding the chain ID part.

const collectionAddress = "0x51790d397e3cC5F418635796e75C8B58EA113f3D"; //Collection Address Here
const collectionName = "FOMOsapiens"; //CollectioonName Here
const chainId = "polygon"
async function generateRarity() {
  const NFTs = await Moralis.Web3API.token.getAllTokenIds({
    address: collectionAddress,
    chain: chainId
  });
  for (let i = pageSize; i < totalNum; i = i + pageSize) {
    const NFTs = await Moralis.Web3API.token.getAllTokenIds({
      address: collectionAddress,
      chain: chainId,
      offset: i,
    });

This stopped it from defaulting to eth, and directed it to polygon. Bingo.

Thanks for the help, Malik. :slight_smile:

2 Likes