0

I have a contract MyContract is ERC721. MyContract needs to concatenate a string with an existing token URI using this function:

string(abi.encodePacked(_tokenURIs[_tokenId], _URI));

Problem is all tokens' URIs are stored in a private variable in the parent ERC721 contract like so

mapping(uint256 => string) private _tokenURIs;

Gas efficiency is a key requirement here. MyContract should not call the standard ERC721 tokenURI getter function: it needs a direct access to the mapping so as to concatenate the strings in one step (concatenation via tokenURI function would involved three steps: fetch initial URI string, concatenate appendice string, push concatenated string).

I'd like to use the standard URI functions provided by ERC721. Is this a dead-end? Can I simply change _tokenURIs mapping from private to internal and still be ERC721 compliant? Is there a work-around where I could directly overwrite _tokenURIs mapping from child contract?

  • 1
    Are you "in control" of the ERC721 contract (i.e., are you the one implementing and deploying it)? If yes, then you can declare that mapping internal, and then inherit from the ERC721 contract. – goodvibration Jun 1 at 7:19
1

Can I simply change _tokenURIs mapping from private to internal and still be ERC721 compliant?

Yes, the ERC721 standard (as any other standard) defines the contract's API, not its internal implementation.

Gas efficiency is a key requirement here.

Inheritting your contract from the ERC721 contract will allow you to read that variable (after declaring it internal) without performing any external function calling.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.