[SOLVED] Updating the token_uri data after updating the baseuri on contract

Hi, I updated my baseURI on my smart contract.
Because I uploaded new images for testing on pinata,
but when I get the data with “Moralis.Web3API.account.getNFTsForContract” I’m not getting the correct token_uri in the results, I’m getting old token_uri.

Do I need to refresh the server?

Also the below code returns empty, am I doing something wrong?
let tokenMetadata = await Moralis.Web3API.token.getTokenMetadata(
metaDataOptions
);
console.log(“TOKEN META DATA:”, tokenMetadata);

Hi,
I don’t know when will Moralis reprocess the NFTs in order to update the the new token uri, it may not be a real time processing for the smart contracts that change their base token uri.

1 Like

thank you for the help, ill keep working on it as it is until it updates.

So I kept testing and what I found out is that new mints do read the correct token_uri.
The already minted ones don’t update, in case anyone bumps into this.

If i remember correct Moralis caches the metadata and if someone requests the particular token after 24h a resync of metadata for the token will trigger

I’m using this:

Moralis.Web3API.account.getNFTsForContract(options).then((data) => {
      let nftsResult = data.result.sort(
        (a, b) => (parseInt(a.token_id) > parseInt(b.token_id) && 1) || -1
      );
      setNfts(nftsResult);
    });

to get my nfts, but I can’t seem to get the updated token_uri after 24hrs, or maybe im doing something wrong, i also check for nfts after a user has recently minted an nft, i see it minted in the smartcontract on ethernet scan, but i don’t see it update in the request above after the mint, I’m trying to show the image linked to the metadata so the user can see it right after they mint it.

Can you use this function on the particular NFT token?
https://docs.moralis.io/moralis-server/web3-sdk/token#gettokenidmetadata

That would trigger a refresh if the cache is older than 24h
So the second time in theory you should get updated version

let me know if that works

I was looking into that function after I posted my last reply, I just tried it, but it didn’t refresh the token_uri, I was basically looking at all the functions in the documentation that could make sense to what I’m trying to do.

You did 2 requests and both returned old data?

And you are sure 24h have passed since initial cache?

I did several requests to that function, but you are right maybe there are still some hours before 24hrs have passed fully, i will come back once 24hrs have truly passed, thank you very much for the assistance!

Ok if 24h have passed and it still doesn’t return new data we need:

  1. exact call you are making with contract address and token id

  2. expected output and received output

Hi Ivan,

address: “0xcb01c3ad7092f2a7fe9de8f166e553cd66694bfd”
chain: “rinkeby”
token_id: “6”

const getMetaData = async () => {
    const options = {
      address: contractAddress,
      token_id: data.token_id,
      chain: networks.rinkeby,
    };
    console.log("options:", options);
    const tokenIdMetadata = await Moralis.Web3API.token.getTokenIdMetadata(
      options
    );
    console.log(tokenIdMetadata);
  };

I tried with several tokens from #3 ~ #6 they all give the same result (not updated token_uri), except the ones minted after the baseURI change.

Expected token_uri:
token_uri: “https://ipfs.moralis.io:2053/ipfs/QmNwX4pmFeVg3DGaNMCBVRbSeTChxMjQTtgMWuz83c9bjm/6.json

received token_uri:
token_uri: “https://ipfs.moralis.io:2053/ipfs/6.json

:pensive: @cryptokid @ivan @Yomoo hi, sorry for bothering you guys, does anybody got any insight on this or point me in the right direction, is what I’m trying to achieve not doable?

Hello, Sorry for the delay.

It should be good now. Can you confirm it’s good on your end.

1 Like

This is working thank you!

2 Likes