Can't find _SetBaseURI() in ERC721 contracts although your doc talks about it

I checked this doc https://docs.openzeppelin.com/contracts/2.x/api/token/erc721#ERC721Metadata-_setBaseURI-string- and it does mention about this function _setBaseURI(string baseURI) but why I can't find it here - https://github.com/athiwatp/openzeppelin-solidity/tree/master/contracts/token/ERC721

Other forum post here said that setting baseURI is expensive so does that mean it's been entirely omitted in favor of setTokenURI?

If you have the same baseUri for all your tokens you can create that function yourself and store it in your own contract.

You have to overwrite it. That's why it appears as "virtual" in the contract ERC721

/**
     * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
     * token will be the concatenation of the `baseURI` and the `tokenId`. Empty
     * by default, can be overriden in child contracts.
     */
    function _baseURI() internal view virtual returns (string memory) {
        return "";
    }

Since you override it you can create the setBaseUri function yourself.

2 Likes

You're looking at the docs for 2.x (see the URL), but the latest version is 4.4! The way base URI is defined now is by overriding the function as shown by @cainuriel.

Right. My bad. But when I googled the older doc appeared. Like this.

I see! Thanks for pointing that out. Will add a notice on older versions of the docs.

This doesn't just happen to you guys. Even web3.js, their old docs often ranked high on Google.

I'd suggest, since blockchain tech evolves so rapidly, have a vivid note on top as you said or put them in a separate URL with the word like "archive" or something to differentiate older versions. Or use the word "latest" in the URL for latest ver. Google is smart these days.

1 Like