What is setBaseURI used for?

Hi everyone!

I wanted some better clarification on setBaseURI and what it is used for.

In abcoathup example, he sets setBaseURI to a link inside the constructor.

Is setBaseURI set once the contract is deployed to a main link, let's say the contracts website domain name?


To set the base uri of where your metadata presides. For example, you have all your metadata hosted on a server with the endpoint as https://www.myserver.com/metadata/<token id> then your base uri is https://www.myserver.com/metadata/.

This helps to reduce the work of having to manually set the URI for each individual NFT.

1 Like

AH! okay okay , that makes sense.

I'm using Fleek to store my metadata, so for my case
https://storageapi.fleek.co/nfts/ would be my base uri.

I'm brainstorming here, but what is the point in that? Couldn't I just as easily assign the whole uri when I use _setTokenURI?

Yeah you could but imagine if you had 10k NFTs, you had to call _setTokenURI 10k times or maybe if you could batch it, you might still need to do it like 500 times whereas with the base URI, you don't need to do this as long as you configure the way you retrieve your URI correct.

For example, if your metadata is stored like https://storageapi.fleek.co/nfts/1, https://storageapi.fleek.co/nfts/2, https://storageapi.fleek.co/nfts/3, https://storageapi.fleek.co/nfts/4 etc. then it makes sense to do something like URI = base URI + token ID.

1 Like