Skip to content

Commit 8d4e965

Browse files
committed
Refactor tokenURI function in ERC20FixedDenomination for improved metadata handling
- Updated the `tokenURI` function to include a revert for invalid token IDs, enhancing error handling. - Simplified JSON metadata construction by removing unnecessary attributes, streamlining the output for fixed denomination tokens.
1 parent d2d9b33 commit 8d4e965

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

contracts/src/ERC20FixedDenomination.sol

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ contract ERC20FixedDenomination is ERC404NullOwnerCappedUpgradeable {
155155
/// @notice Returns metadata URI for NFT tokens
156156
/// @dev Returns a data URI with JSON metadata fetched from the main Ethscriptions contract
157157
function tokenURI(uint256 id_) public view virtual override returns (string memory) {
158+
// This will revert InvalidTokenId / NotFound on bad ids
159+
ownerOf(id_);
160+
158161
uint256 mintId = id_ & ~ID_ENCODING_PREFIX;
159162

160163
// Get the ethscriptionId for this mintId from the manager
@@ -181,7 +184,7 @@ contract ERC20FixedDenomination is ERC404NullOwnerCappedUpgradeable {
181184
// Build the JSON metadata
182185
string memory jsonStart = string.concat(
183186
'{"name":"', name(), ' Note #', mintId.toString(), '"',
184-
',"description":"Fixed denomination note for ', mintAmount().toString(), ' ', symbol(), ' tokens"'
187+
',"description":"Fixed denomination token for ', mintAmount().toString(), ' ', symbol(), ' tokens"'
185188
);
186189

187190
// Add ethscription ID and number
@@ -195,16 +198,7 @@ contract ERC20FixedDenomination is ERC404NullOwnerCappedUpgradeable {
195198
',"', mediaType, '":"', mediaUri, '"'
196199
);
197200

198-
// Add attributes
199-
string memory attributesJson = string.concat(
200-
',"attributes":[',
201-
'{"trait_type":"Note ID","value":"', mintId.toString(), '"},',
202-
'{"trait_type":"Denomination","value":"', mintAmount().toString(), '"},',
203-
'{"trait_type":"Token","value":"', symbol(), '"}',
204-
']'
205-
);
206-
207-
string memory json = string.concat(jsonStart, ethscriptionFields, mediaField, attributesJson, '}');
201+
string memory json = string.concat(jsonStart, ethscriptionFields, mediaField, '}');
208202

209203
return string.concat("data:application/json;base64,", Base64.encode(bytes(json)));
210204
}

0 commit comments

Comments
 (0)