Giter Club home page Giter Club logo

Comments (6)

emirhansirkeci avatar emirhansirkeci commented on July 19, 2024 1

I set totalNum to calculate rarity scores. Cursor usage is giving us the full metadata of any collection. I thing setting the variable like this after loop is completed may be way better than my codes. let totalNum = allNFTs.length;

And like that you don't have to know how many NFT's are available in collection.

from rarity-ranking-nft.

Deveshb15 avatar Deveshb15 commented on July 19, 2024

Same issue for me, is there a fix for this?

from rarity-ranking-nft.

emirhansirkeci avatar emirhansirkeci commented on July 19, 2024

Same issue for me, is there a fix for this?

I used cursor instead of offset.

async function generateRarity() {
  const totalNum = 10000;
  let allNFTs = [];

  const timer = (ms) => new Promise((res) => setTimeout(res, ms));

  let cursor = null;
  do {
    const response = await Moralis.Web3API.token.getAllTokenIds({
      address,
      chain: "eth",
      limit: 500,
      cursor: cursor,
    });
    console.log(
      `Got page ${response.page} of ${Math.ceil(
        response.total / response.page_size
      )}, ${response.total} total`
    );
    allNFTs = allNFTs.concat(response.result);
    cursor = response.cursor;
    // await timer(1000);
    cursor = null; // disable the timer above and enable this line of code to get only 500 tokenIds;
  } while (cursor != "" && cursor != null);

  let metadata = allNFTs.map((e) => JSON.parse(e.metadata).attributes);
  console.log(metadata);

from rarity-ranking-nft.

Deveshb15 avatar Deveshb15 commented on July 19, 2024

Same issue for me, is there a fix for this?

I used cursor instead of offset.

async function generateRarity() {
  const totalNum = 10000;
  let allNFTs = [];

  const timer = (ms) => new Promise((res) => setTimeout(res, ms));

  let cursor = null;
  do {
    const response = await Moralis.Web3API.token.getAllTokenIds({
      address,
      chain: "eth",
      limit: 500,
      cursor: cursor,
    });
    console.log(
      `Got page ${response.page} of ${Math.ceil(
        response.total / response.page_size
      )}, ${response.total} total`
    );
    allNFTs = allNFTs.concat(response.result);
    cursor = response.cursor;
    // await timer(1000);
    cursor = null; // disable the timer above and enable this line of code to get only 500 tokenIds;
  } while (cursor != "" && cursor != null);

  let metadata = allNFTs.map((e) => JSON.parse(e.metadata).attributes);
  console.log(metadata);

Even I tried this but what if the collection has more than 10000 nfts?

from rarity-ranking-nft.

thomasansems avatar thomasansems commented on July 19, 2024

#16 Created a pull request regarding the updated cursor of Moralis.

from rarity-ranking-nft.

Arkay92 avatar Arkay92 commented on July 19, 2024

This works as a fix for cursor

` let allNFTs = [];

const timer = (ms) => new Promise((res) => setTimeout(res, ms));

let cursor = null;
do {
const NFTs = await Moralis.Web3API.token.getAllTokenIds({
address: collectionAddress,
chain: "eth",
limit: 100,
cursor: cursor,
});

  let counter = 0;

  for (const nft of NFTs.result) {
        let metaData = JSON.parse(nft.metadata);
        if(metaData != null) {
           allNFTs.push(nft);
           console.log(metaData);
        }
        counter+=100;
  }

  if(counter % 200 == 0) {
      await timer(2000);
  }

  cursor = NFTs.cursor;

} while (cursor != "" && cursor != null);

let metadata = allNFTs.map((e) => {
if(JSON.parse(e.metadata)) {
return JSON.parse(e.metadata).attributes
}
});`

from rarity-ranking-nft.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.