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 the rarity of each attribute of an NFT.


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


Promise<ComputeRarityResponse>objectThe response object for the method.

ComputeRarityResponse object properties

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

rarities response properties

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
yarn add alchemy-sdk@latest


// Imports the Alchemy SDK
const { Alchemy, Network } = require("alchemy-sdk");

// Configures the Alchemy SDK
const config = {
    apiKey: "alchemy-replit", // Replace with your API key
    network: Network.ETH_MAINNET, // Replace with your network

// Creates an Alchemy object instance with the config to use for making requests
const alchemy = new Alchemy(config);

const main = async () => {
    // define the contract address and tokenId
    const address = "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d";
    const tokenId = 145;

    //Call the method to display the rarity of each attribute of the NFT
    const response = await alchemy.nft.computeRarity(address, tokenId)

    //Logging the response to the console



    "rarities": [
            "traitType": "Background",
            "value": "Orange",
            "prevalence": 0.1273
            "traitType": "Hat",
            "value": "Prussian Helmet",
            "prevalence": 0.013
            "traitType": "Mouth",
            "value": "Bored Unshaven",
            "prevalence": 0.1551
            "traitType": "Fur",
            "value": "Black",
            "prevalence": 0.1229
            "traitType": "Clothes",
            "value": "Bone Necklace",
            "prevalence": 0.0203
            "traitType": "Eyes",
            "value": "3d",
            "prevalence": 0.0487

Code Sandbox

You can test out the computeRarity method using the code sandbox below:

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.