Skip to content

Instantly share code, notes, and snippets.

@schmidsi
Created January 16, 2022 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schmidsi/eafea8105f5971f404e8337874460536 to your computer and use it in GitHub Desktop.
Save schmidsi/eafea8105f5971f404e8337874460536 to your computer and use it in GitHub Desktop.
Example how to create a JSON from solidity
function makeJSON() public view virtual returns (string memory) {
return
string(
abi.encodePacked(
"data:application/json;base64,",
Base64.encode(
abi.encodePacked(
'{"name": "Bla #',
tokenId.toString(),
'", "description": "Description",',
'"image": "', _baseURI(), 'api/token/', tokenId.toString(), '.svg",'
'"external_url": "', _baseURI(), 'token/', tokenId.toString(), '",'
'"attributes": [{ "trait_type": "A", "value": "',
"1",
'"}, { "trait_type": "B", "value": "',
"2",
'"}, { "trait_type": "C", "value": "',
"3",
'"}, { "trait_type": "D", "value": "',
"4",
'"}, { "trait_type": "E", "value": "',
"5",
'"}, { "trait_type": "F", "value": "',
"6",
'"}]}'
)
)
)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment