What do I need to change in that code that I already have to see the files that has a…
- User
What do I need to change in that code that I already have to see the files that has a .json at the end because it doesn't work for the moment:
string public baseTokenURI = "ipfs://URI/"; function _baseURI() internal view virtual override returns (string memory) { return baseTokenURI; } function setBaseURI(string calldata _newBaseURI) external onlyOwner { require(!metadataFrozen, "METADATA_HAS_BEEN_FROZEN"); baseTokenURI = _newBaseURI; } - Assistant
To ensure that your Solidity contract only allows the setting of base URIs that end with ".json," you will need to modify the
setBaseURIfunction to include a validation check. Specifically, you can verify that the new base URI string ends with ".json" before allowing the change to take place. - User
What do I need to change in that code that I already have to see the files that has a .json at the end because it doesn't work for the moment. JUST WRITE IT, DON'T EXPLAIN ME:
string public baseTokenURI = "ipfs://URI/";
function _baseURI() internal view virtual override returns (string memory) { return baseTokenURI; }
function setBaseURI(string calldata _newBaseURI) external onlyOwner { require(!metadataFrozen, "METADATA_HAS_BEEN_FROZEN"); baseTokenURI = _newBaseURI; }
- Assistant
string public baseTokenURI = "ipfs://URI/"; function _baseURI() internal view virtual override returns (string memory) { return baseTokenURI; } function setBaseURI(string calldata _newBaseURI) external onlyOwner { require(!metadataFrozen, "METADATA_HAS_BEEN_FROZEN"); require(bytes(_newBaseURI).length >= 5 && keccak256(abi.encodePacked(substr(_newBaseURI, bytes(_newBaseURI).length - 5, 5))) == keccak256(abi.encodePacked(".json")), "Base URI must end with .json"); baseTokenURI = _newBaseURI; } function substr(string memory str, uint start, uint length) internal pure returns (string memory) { bytes memory strBytes = bytes(str); bytes memory result = new bytes(length); for (uint i = 0; i < length; i++) { result[i] = strBytes[start + i]; } return string(result); }