Moralis API not updating owner_of after NFT transfer

I have a marketplace app where each NFT item gets its data from that getTokenIdMetadata endpoint.

When a user purchases an item react query runs a mutation and refetches the data however, it refetches getTokenIdMetadata which returns data with the last owner_of and not the new owner.

I’ve tried running reSyncMetadata endpoint for the token ID as well but the owner data does not update.

What’s the best way to get the Moralis API data to refresh?

I’m testing running both endpoints from the API docs here and the data doesn’t update:

https://deep-index.moralis.io/api-docs/#/token/getTokenIdMetadata

it should update automatically, you can not force this update with resync endpoint

what is the delay that you saw and on what chain?

It’s on polygon and the on-chain data updates immediately.

The getNFTsForContract endpoint does update automatically right away:
https://deep-index.moralis.io/api-docs/#/account/getNFTsForContract

But getTokenIdMetadata does not

More than 20 minutes later getTokenIdMetadata still hasn’t updated

ok, so it looks like a caching issue for getTokenIdMetadata

do you have an example that doesn’t work now

address: 0x67f4732266c7300cca593c814d46bee72e40659f
tokenId: 183465

owner_of should be showing: 0x9396c0fED2aF8257F59437F461De1c8fF7b06630

this is not the expected behaviour, we’ll have to investigate

1 Like

if you try it again with a new transfer you get same behaviour?

did you check the result of getTokenIdMetadata multiple times while you were making that transfer?

Yes, I just tried again and got the same issue. It isn’t updating owner_of

Txn: https://polygonscan.com/tx/0x43d90e275dcdfdb49afaaaf143b7a71f7cb647e90e0e2e05fc16fcd67112d4ca

If I test here with token Id and contract it still shows old owner:

https://deep-index.moralis.io/api-docs/#/token/getTokenIdMetadata

how many calls did you do to getTokenIdMetadata close to the time of the transfer? there is a possible race condition if you make a lot of calls

a few seconds after the transfer I invalidate the react query cache and it refetches from that API so once only.

Then I manually tried to fetch from the API docs.

The transfer I did last night eventually updated in getTokenIdMetadata hours later

It will work after few hour because the cache ttl expires at that time. But it should work much faster.

What do you think a solution would be?

I’m not sure yet what happens in this case. I would not expect it to happen so easily only with 2-3 requests to getTokenIdMetadata endpoint.

If you make few requests before the transfer and one request after 1 minute after the transfer then I would expect it to work without issues.

Could this be a bug with the API that could be escalated to the dev team to look at?

yes, it is a bug that is already escalated, I’m not sure what are the circumstances when it replicates in your particular case as it seems to replicate quite easily