How to get the rarity and traits of an NFT?

For most NFTs, excluding factors such as project endorsement and image artistry, Rarity and Trait are the most influential factors in their price. Under the same project, the price of NFTs with high rarity ranking or carrying certain particular traits can reach several times or even tens of times of the floor price.

Take the well-known blue chip Azuki for example, the floor price of the project on January 2, 2023, is around 14eth. However, the floor price of NFT with type as spirit simultaneously can reach 199eth, and the highest ever transaction price of the trait is over 400eth.

If you are developing any application with an NFT display function, such as community tools, trading platforms, data analysis platforms, etc., we provide you with real-time, comprehensive NFT Trait data, as well as generic and realistic Rarity algorithms, eliminating the complex process of building nodes, acquiring metadata and designing algorithms, reducing development costs while saving human resources.

1280

Retrieve basic information of an NFT

To call this endpoint, you need to fill in two parameters

  • contract_address (string): Address of the contract for an NFT collection, beginning with 0x
  • token_id (integer): The token ID for the specific NFT. Each NFT will be assigned a unique id, the value generally ranges from 1 to N, with N being the total number of NFTs in a collection.

And add the following code to the main.js

import fetch from 'node-fetch';

// Replace with your NFTGo API key:
const apiKey = "YOUR-API-KEY";
const options= {
  method: 'GET',
  headers: {
    accept: 'application/json',
    'X-API-KEY': apiKey
  }
};
// Replace with the contract address you want to query:
const contractAddress = "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d"
// Replace with the token id you want to query:
const tokenId = "4495"
const url = `https://data-api.nftgo.io/eth/v1/nft/${contractAddress}/${tokenId}/info`;

// Make the request and print the formatted response:
fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error('error:' + err));

Your output should look like this.

{
  "blockchain": "ETH",
  "collection_name": "Bored Ape Yacht Club",
  "collection_slug": "bored-ape-yacht-club",
  "collection_opensea_slug": "boredapeyachtclub",
  "contract_address": "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D",
  "token_id": "4495",
  "name": "Bored Ape Yacht Club #4495",
  "description": "string",
  "image": "https://static.nftgo.io/asset/metadata/image/5e236a5b9e95e4b88df604399ea7ca56229fdf86b9b8da78a6fd587a155b8b98",
  "animation_url": "string",
  "owner_addresses": [
    "0xcaf1d788c67BdAAC155E7dcC4D64e2004eF651D4"
  ],
  "traits": [
    {
      "type": "Eyes",
      "value": "Wide Eyed",
      "percentage": 0.0549
    },
    {
      "type": "Background",
      "value": "Aquamarine",
      "percentage": 0.1266
    },
    {
      "type": "Fur",
      "value": "Black",
      "percentage": 0.1229
    },
    {
      "type": "Mouth",
      "value": "Bored",
      "percentage": 0.2272
    },
    {
      "type": "Clothes",
      "value": "Service",
      "percentage": 0.0142
    }
  ],
  "rarity": {
    "score": 34.72,
    "rank": 9152,
    "total": 10000
  }
}

Retrieve rarity ranking of an NFT

To call this endpoint, you need to fill in two parameters

  • contract_address (string): Address of the contract for an NFT collection, beginning with 0x
  • token_id (integer): The token ID for the specific NFT. Each NFT will be assigned a unique id, the value generally ranges from 1 to N, with N being the total number of NFTs in a collection.

And add the following code to the main.js

import fetch from 'node-fetch';

// Replace with your NFTGo API key:
const apiKey = "YOUR-API-KEY";
const options= {
  method: 'GET',
  headers: {
    accept: 'application/json',
    'X-API-KEY': apiKey
  }
};
// Replace with the contract address you want to query:
const contractAddress = "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d"
// Replace with the token id you want to query:
const tokenId = "4495"
const url = `https://data-api.nftgo.io/eth/v1/nft/${contractAddress}/${tokenId}/rarity`;
;

// Make the request and print the formatted response:
fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error('error:' + err));

Your output should look like this.

{
  "score": 34.72,
  "rank": 9152,
  "total": 10000,
  "last_updated": 1652598929
}