0

I am running in a issue related to tokenURI(). This is my function:

function initialize(string memory _baseUri) public initializer { __ERC721_init("GAME", "GM"); __Ownable_init(); baseUri = _baseUri; } function mint(address _address) internal { tokenId.increment(); uint256 currentTokenId = tokenId.current(); _safeMint(_address, currentTokenId); tokenURI(currentTokenId); } 

I passed my metadata file's url which is this as baseURI. After deploying when i queried the value of tokenURI it shows this: https://gateway.pinata.cloud/ipfs/QmaU1NBQczTWYz7cbhJDSeEugyhYPRoZrFPfcRxMkvQ79t1 for tokenId 1. When i gone to the link it shows this error: ipfs resolve -r /ipfs/QmaU1NBQczTWYz7cbhJDSeEugyhYPRoZrFPfcRxMkvQ79t1: invalid path "/ipfs/QmaU1NBQczTWYz7cbhJDSeEugyhYPRoZrFPfcRxMkvQ79t1": invalid CID: selected encoding not supported. What is the issue?

1 Answer 1

1

This problem is because of wrong concatenation.

This is the function I use to concatenate the URI

 function getUri(uint256 _tokenId) internal view returns (string memory) { return string( abi.encodePacked(baseUri, Strings.toString(_tokenId), ".json") ); } 

Check out full code here : https://github.com/Zartaj0/ERC1155/blob/c1f8ef450630b30065f876889288469d72ac539f/contracts/Joker.sol#L54

4
  • so my code is write, i will override the tokenURI() and edit. Commented Apr 28, 2023 at 19:16
  • But I just saw your baseURI which is a single files URI. So what is the point of concatenation in it? BaseURI folders look like this then you can add 1.json or 2.json or 3.json and it will direct you to a particular file. gateway.pinata.cloud/ipfs/… Commented Apr 29, 2023 at 3:12
  • But why it is not working with 1 file? we have same code to get tokenURI, right? no matter it is a folder or single file. Commented Apr 29, 2023 at 5:45
  • Because 1 file can be a token URI of a single token. When you say base URI, it means you are defining a single URI where the Token URIs of each token exist. So it needs to be a folder if you are working with base URI. But if you want each token to have a different URI then you can pass empty strings to BaseURI and pass URI for every token. Commented Apr 30, 2023 at 14:58

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.