I hope I can describe the problem properly.
Let's say I have 100 NFT tokens stored in an IPFS storage at some location say,
ipfs://abc
I have a smart contract ready where I use the constructor to set the base URI:
constructor(
string memory _initBaseURI
) ERC721("MyTestTokens", "MTT") {
setBaseURI(_initBaseURI);
}
I deploy the contract by passing "ipfs://abc/"
as the argument.
I can use the TokenURI function to get any token information (say ipfs://abc/50.json
).
Now lets I have more 100 tokens which I stored in ipfs://xyz
.
I can use the setbaseURI function to set the new base URI in the smart contract:
// set baseURI
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
I can call the function and pass the argument: "ipfs://xyz/"
Now the problem is, if I want to get the token URI information of the first 100 tokens then it return:
string(abi.encodePacked(currentBaseURI, tokenId.toString(), baseExtension))
Which is ipfs://xyz/1.json
(for first token).
Since 1.json is stored in ipfs://abc/
, it will give a 404 error
(or something like this)
Any suggestion on what to do here?