Created
November 11, 2021 00:24
-
-
Save korrio/229ed06ccfca283aa8618fd22d8019fe to your computer and use it in GitHub Desktop.
tokenURI.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function tokenURI(uint256 _tokenId) | |
public | |
view | |
override | |
returns (string memory) | |
{ | |
CharacterAttributes memory charAttributes = nftHolderAttributes[ | |
_tokenId | |
]; | |
string memory strHp = Strings.toString(charAttributes.hp); | |
string memory strMaxHp = Strings.toString(charAttributes.maxHp); | |
string memory strAttackDamage = Strings.toString( | |
charAttributes.attackDamage | |
); | |
string memory json = Base64.encode( | |
bytes( | |
string( | |
abi.encodePacked( | |
'{"name": "', | |
charAttributes.name, | |
" -- NFT #: ", | |
Strings.toString(_tokenId), | |
'", "description": "This is an NFT that lets people play in the game Metaverse Slayer!", "image": "', | |
charAttributes.imageURI, | |
'", "attributes": [ { "trait_type": "Health Points", "value": ', | |
strHp, | |
', "max_value":', | |
strMaxHp, | |
'}, { "trait_type": "Attack Damage", "value": ', | |
strAttackDamage, | |
"} ]}" | |
) | |
) | |
) | |
); | |
string memory output = string( | |
abi.encodePacked("data:application/json;base64,", json) | |
); | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment