4

I wanted to store the metadata of my ERC721 tokens on IPFS. Currently, I am inheriting from OpenZeppelin ERC721.sol contract, and I saw there is a tokenURI function which returns the URI of the metadata. This token URI function build its URI based on the baseURI concatenated with the tokenID. The thing is if I would like to store on IPFS, the URI will be the hash of the content stored, and it will be nowhere close to the URI built by the tokenURI function. Thus I am unsure of how to build the tokenURI in my case? (of course I could build it manually, but is there a way to write a function to automate this?)

1 Answer 1

3

Set your _baseURI as "ipfs://" and put the content hash into _tokenURI.

The relevant code is at https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/ERC721.sol#L141-L144

The result is your tokenURI(tokenID) will be the full IPFS URI.

1
  • this answer is now outdated
    – PedroD
    Nov 9, 2021 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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