How to set NFTOwners table automatically to tokenURI istead of token_uri

the NFTOwners table automatically sets the tokenURI class column to (token_uri) but my NFT contract uses (TokenURI), is there a way to change it from token_uri ,to tokenURI and have the database recognize it. I created a new column named tokenURI but it doesn’t register the token uri

Hey @xavierx

You can use beforesave trigger (docs)

I’ll send you an example

okay please send an example, thanks

beforeconsume trigger*

Moralis.Cloud.beforeConsume('NFTOwners', async (event) => {
  event.tokenURI = event.token_uri;
  delete event.token_uri;
  return event;
1 Like

unfortunately this doesn’t work. I don’t know if this matters but i’m using chainlink VRF to generate the nft’s and My code doesn’t set tokenURI when the NFT is minted, i do that manually after a few nfts have been minted.

Can’t you start from beginning by modifying the smart contract to add token_uri?

Unfortunately i’m using openzeppelin erc721 contract and the set token uri function is defined as

function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual {
require(_exists(tokenId), “ERC721Metadata: URI set of nonexistent token”);
_tokenURIs[tokenId] = _tokenURI;

You can use method from @cryptokid and manually change the event name in the ABI

an example of ERC721 token:
an example of NFT for that ERC721 smart contract:
it looks like there is no token_uri in that smart contract code

but somehow when running:

options_2 = { address: "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D", token_id: "9136", chain: "eth" };
tokenIdMetadata_2 = await Moralis.Web3API.token.getTokenIdMetadata(options_2)

it will display token_uri:

{token_address: "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d", token_id: "9136", contract_type: "ERC721", token_uri: "", metadata: null, …}
amount: "1"
contract_type: "ERC721"
metadata: null
name: "BoredApeYachtClub"
symbol: "BAYC"
synced_at: null
token_address: "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d"
token_id: "9136"
token_uri: ""

I think for my version of solidity and openzeppelin contract the tokenURI is specified as tokeURI not token_uri so trying to rewrite the function throws an error. Most recent NFT contracts are using the tokenURI statement

I’m not sure what is going on, token_uri could also be something computed and added by Moralis when it processes the NFTs. In the example above it looks like the contract didn’t have token_uri but at the end there is an IPFS link on Moralis IPFS for an NFT that probably was not created with Moralis.