i tried what frangio said but never got it working. i'm totally new to solidity/javascript, but im pretty sure what he said is right.
starting to go off topic now, but when i tried i didnt know how to use "padStart" function. im compiling with remix solidity and that gave me an error. maybe missing some imports. i also tried importing the toString but that didnt fix it. hope you had better luck
@NothingBurger26, It did not work for you because what you have shared @frangio is javascript code for your front.
It is not solidity code.
Think of your smart contract as the back of a web application. The data returned by the uri function must be manipulated so that they generate the recommended uri in the EIP
What you have to do is create the front of a dapp to receive the response from the uri function connecting to the blockchain through one of the most used javascript libraries: Ethers.js or Web3.js
You can also use either of the two most popular development environments:
Sharing a solution to getting URI function to output tokenURI with the padding and in hex without further modification on the front end! Let me know if you guys like it
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
function toHexString(uint256 value, uint256 length) public pure returns (string memory) {
bytes memory buffer = new bytes(length+2);
for (uint256 i = length + 1; i > 1; --i) {
buffer[i] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
function uri(uint256 _tokenID) override public view returns (string memory) {
return string(abi.encodePacked(baseURI,toHexString(_tokenID,64),".json"));
}