computeRarity - SDK

Returns the floor prices of an NFT contract by marketplace.

Don’t have an API key?

Start using this method in your app today. Get started for free

Please note that this endpoint is only available on Ethereum (mainnet) & Polygon (mainnet & mumbai)

Description

Get the rarity of each attribute of an NFT.

Parameters

NameTypeDescription
contractAddressstringThe contract address of the NFT collection.
tokenIdstringToken id of the NFT.

Response

PropertyTypeDescription
Promise<ComputeRarityResponse>objectThe response object for the method.

ComputeRarityResponse object properties

ParameterTypeDescription
raritiesarray of objectsSummary of the attribute prevalence for the specified NFT contract.

rarities response properties

PropertyTypeDescription
valuestringName of the NFT’s attribute.
traitTypestringThe type of NFT attribute.
prevalencenumberA number from 0 to 1represents this value’s prevalence for this trait type in the current collection.

Example Request and Response

Prerequisite: You must install the Alchemy SDK before making requests with it.

The commands for installing it using npm or yarn are given below:

$npm install alchemy-sdk@latest

Request

index.js
1// Imports the Alchemy SDK
2const { Alchemy, Network } = require("alchemy-sdk");
3
4// Configures the Alchemy SDK
5const config = {
6 apiKey: "alchemy-replit", // Replace with your API key
7 network: Network.ETH_MAINNET, // Replace with your network
8};
9
10// Creates an Alchemy object instance with the config to use for making requests
11const alchemy = new Alchemy(config);
12
13const main = async () => {
14 // define the contract address and tokenId
15 const address = "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d";
16 const tokenId = 145;
17
18 //Call the method to display the rarity of each attribute of the NFT
19 const response = await alchemy.nft.computeRarity(address, tokenId)
20
21 //Logging the response to the console
22 console.log(response)
23}
24
25main();

Response

json
1{
2 "rarities": [
3 {
4 "traitType": "Background",
5 "value": "Orange",
6 "prevalence": 0.1273
7 },
8 {
9 "traitType": "Hat",
10 "value": "Prussian Helmet",
11 "prevalence": 0.013
12 },
13 {
14 "traitType": "Mouth",
15 "value": "Bored Unshaven",
16 "prevalence": 0.1551
17 },
18 {
19 "traitType": "Fur",
20 "value": "Black",
21 "prevalence": 0.1229
22 },
23 {
24 "traitType": "Clothes",
25 "value": "Bone Necklace",
26 "prevalence": 0.0203
27 },
28 {
29 "traitType": "Eyes",
30 "value": "3d",
31 "prevalence": 0.0487
32 }
33 ]
34}

Use Cases

Here are some potential use cases for the computeRarity method:

  • NFT marketplaces: NFT marketplaces such as OpenSea, Rarible, and SuperRare use the computeRarity method to calculate the rarity score of different NFTs helps determine their value in the marketplace.

  • NFT collections: NFT collections such as CryptoKitties and CryptoPunks use the computeRarity method to determine the rarity of each NFT in their collection, which adds to the overall uniqueness and value of the collection.

  • Gaming applications: Gaming applications that use NFTs often use the computeRarity method to calculate the rarity of different game items, such as weapons or armor, which can affect their in-game performance and value.