How to get nft owner by token id
Prerequisites
Before getting started, make sure you have the following ready:
- Node v.14+
- NPM
Step 1: Setup Blocklens
First register your Blocklens account and get your Blocklens API Key.
Once you have your Blocklens API Key, install the Blocklens SDK in your project.
npm i blocklens-sdk
Step 2: Get NFT owner by token id
In order to get nft owner by token id, Blocklens provides you a getNftOwnerByTokenId endpoint to do so.
Here you'll need parameters: address
, token_id
.
Once you've obtained all the address
, token_id
, you can copy the following code:
import Blocklens from "blocklens-sdk";
const blocklens = new Blocklens();
blocklens.init({ apiKey: "YOUR_API_KEY" });
const runApis = async () => {
const response = await blocklens.ETH_MAINNET.getNftOwnerByTokenId("0x6339e5E072086621540D0362C4e3Cea0d643E114", "12740");
console.log(response);
};
runApis();
Step 3: Run the script
ts-node index.ts
In your terminal, you should see the following JSON response with the data: In your terminal, you should see the following JSON response with the data blocks:
{
"cursor": "string",
"page": 0,
"limit": 0,
"total_items": 0,
"data": [
{
"collection_address": "string",
"collection_type": "string",
"token_id": "string",
"token_hash": "string",
"owner_of": "string",
"minter_address": "string",
"amount": "string",
"token_uri": "string",
"metadata": {
"name": "string",
"description": "string",
"image": "string",
"external_link": "string",
"animation_url": "string",
"attributes": [
{
"trait_type": "string",
"value": "string",
"max_value": 0,
"trait_count": 0,
"order": 0
}
]
},
"block_number_minted": 0,
"tx_hash_minted": "string",
"block_number_updated": 0,
"last_token_uri_sync": 0,
"last_metadata_sync": 0
}
]
}
Congratulations 🥳 you just found the get nft owner by token id on multiple chains with only a few lines of code using the Blocklens Wallet API!
API Reference
If you want to know more details on the endpoint and optional parameters, check out:
Support
If you face any trouble following the tutorial, feel free to reach out to our community engineers in our Discord or Forum to get 24/7 developer support.