Retrieving an exact NFT by address and token ID

So, very impressed with how Moralis is able to retrieve all that data for tons and tons of NFTs for a given address, but I was wondering what the correct way is for retrieving a single NFT by its address and token id.

I was able to find this web3 Api which look EXACTLY like what I’m looking for, and I’ve watched Ivan’s video explaining what it is, but I haven’t been able to find anything explaining how to actually call it from the frontend JavaScript.

Please help!

I think that what you found there is getTokenIdMetadata function from Moralis sdk:


const options = { address: "0xd...07", token_id: "1", chain: "bsc" };
const tokenIdMetadata = await Moralis.Web3API.token.getTokenIdMetadata(options);

2 Likes

Thank you. This method seems to work well for some address and token_id pairs, but not so well for others.

For example, the address and id from this NFT: https://opensea.io/assets/0x50e712b3a260d7639179e8277836253461418f23/3532 works perfectly well.

But the address and id from this NFT: https://opensea.io/assets/0x495f947276749ce646f68ac8c248420045cb7b5e/109243918961687695430420208234111469322458866391792481707832184139082708811777

Returns error logs

POST https://hteppc7vx3fc.usemoralis.com:2053/server/functions/getTokenIdMetadata 400

and

{code: 141, error: '[object Object]'}

This doesn’t work because this NFT is not on blockchain, it is only in an internal database on opensea and it will be on blockchain when someone buys it (it is called lazy minting).

1 Like

how can we retrieve the image of this specific tokenId?
do you have a code where I can be based on ?

what is the token id? how can you see the image of that token id now?

token_id .
I Can see it using useNFTBalances()
but this function fetch all the nfts and not specific ones

this is the function specific to a token id: getTokenIdMetadata
https://docs.moralis.io/moralis-dapp/web3-sdk/token#gettokenidmetadata

thank for your answer, I can’t see this function already provided with hooks on ethereum boilerplate?
do you know the name of it, or it is not existing?

I think that you can use this: