# NFT Information and Rarity

You can calculate rarity and ranking for your collection or any other on chain collection. The steps as follows:

* Retrieve NFT information and calculate trait percentage.
* Calculate rarity score and rank based on NFT information file from previous step. We support 4 type of rarity including:
  * Trait Rarity Model
  * Mean/Average Trait Rarity Model
  * Statistical Rarity Model
  * Rarity Score Model

For more information on rarity model calculation, please visit this [great blog post](https://hackernoon.com/how-to-calculate-the-rarity-of-an-nft) about NFT rarity.

Please, make sure that you are in the `js/cli` directory before you proceed with this step.

### Create NFT Information for Your  Collection

```
npx ts-node src/rarity-cli.ts calculate-trait -d data -c data/master.csv -m example-assets/metadata -cn soil -cd "test collection"
```

<table><thead><tr><th width="180">Param</th><th width="107">Required</th><th width="161">Example</th><th>Description</th></tr></thead><tbody><tr><td>-d, --data &#x3C;string></td><td>true</td><td>data</td><td>Data folder that store created NFT contract information</td></tr><tr><td>-c, --config &#x3C;string></td><td>true</td><td>data/master.csv</td><td>MasterCSV file</td></tr><tr><td>-m, --metadata &#x3C;string></td><td>true</td><td>example-assets/metadata</td><td>Metadata folder</td></tr><tr><td>-cn, --name &#x3C;string></td><td>false</td><td>Soil</td><td>Name</td></tr><tr><td>-cd, --description &#x3C;string></td><td>false</td><td>"Soil Collection"</td><td>Description</td></tr><tr><td>-o, --output &#x3C;string></td><td>false</td><td>nfts.json</td><td>NFT information output file name</td></tr></tbody></table>

```
update nft information file: data/nfts.json
```

You will be greeted with this after its calculate collection trait successfully.

### Create NFT Information for On Chain  Collection

```
npx ts-node src/rarity-cli.ts calculate-trait-onchain -d data -c terra16ds898j530kn4nnlc7xlj6hcxzqpcxxk4mj8gkcl3vswksu6s3zszs8kp2 -n mainnet
```

<table><thead><tr><th width="175">Param</th><th width="93">Required</th><th width="195">Example</th><th>Description</th></tr></thead><tbody><tr><td>-d, --data &#x3C;string></td><td>true</td><td>data</td><td>Data folder that store created NFT contract information</td></tr><tr><td>-c, --contract &#x3C;string></td><td>true</td><td>terra16ds898j530kn4nnlc7xlj6hcxzqpcxxk4mj8gkcl3vswksu6s3zszs8kp2</td><td>Contract address</td></tr><tr><td>-n, --network &#x3C;string></td><td>true</td><td>mainnet</td><td>Terra network. (localterra, testnet and mainnet)</td></tr><tr><td>-h, --height &#x3C;number></td><td>false</td><td>1000000</td><td>Block height that you want to snapshot. (Can use only mainnet)</td></tr><tr><td>-o, --output &#x3C;string></td><td>false</td><td>galactic.json</td><td>NFT information output file name</td></tr></tbody></table>

```
find total token id...
████████████████████████████████████████ 100% | ETA: 0s | 3953/3953
finding nft information...
████████████████████████████████████████ 100% | ETA: 0s | 3953/3953
update nft information file: data/terra16ds898j530kn4nnlc7xlj6hcxzqpcxxk4mj8gkcl3vswksu6s3zszs8kp2_nfts.json
```

You will be greeted with this after its calculate collection trait successfully.

### Calculate Rarity

```
npx ts-node src/rarity-cli.ts calculate-rarity -d data -i data/terra16ds898j530kn4nnlc7xlj6hcxzqpcxxk4mj8gkcl3vswksu6s3zszs8kp2_nfts.json
```

<table><thead><tr><th width="130">Param</th><th width="109">Required</th><th width="190">Example</th><th>Description</th></tr></thead><tbody><tr><td>-d, --data &#x3C;string></td><td>true</td><td>data</td><td>Data folder that store created NFT contract information</td></tr><tr><td>-i, --input &#x3C;string></td><td>true</td><td>data/terra16ds898j530kn4nnlc7xlj6hcxzqpcxxk4mj8gkcl3vswksu6s3zszs8kp2_nfts.json</td><td>Input NFT information file from calculate-trait/calculate-trait-onchain command.</td></tr><tr><td>-o, --output &#x3C;string></td><td>false</td><td>galactic_rank</td><td>Output rarity file name in csv format</td></tr></tbody></table>

```
calculate rarity score... 
updated collection file: data/terra16ds898j530kn4nnlc7xlj6hcxzqpcxxk4mj8gkcl3vswksu6s3zszs8kp2_nfts.json 
rank file created at: data/rank_terra16ds898j530kn4nnlc7xlj6hcxzqpcxxk4mj8gkcl3vswksu6s3zszs8kp2.csv
```

You will be greeted with this after its calculate collection rarity successfully.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.soilprotocol.xyz/nft-tooling/nft-information-and-rarity.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
