From a7ce1459c5e08a4abaff3fbc7e9b3c9b2a41eb7f Mon Sep 17 00:00:00 2001 From: Gerald Bauer Date: Sun, 15 Jan 2023 19:04:09 +0100 Subject: [PATCH] up --- ethlite-contracts/README.md | 83 +++++++++++++++++++++++++- ethlite-contracts/punksmeta/punk0.json | 23 +++++++ ethlite-contracts/punksmeta/punk0.svg | 1 + 3 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 ethlite-contracts/punksmeta/punk0.json create mode 100644 ethlite-contracts/punksmeta/punk0.svg diff --git a/ethlite-contracts/README.md b/ethlite-contracts/README.md index 6dc2d4a..78ca85b 100644 --- a/ethlite-contracts/README.md +++ b/ethlite-contracts/README.md @@ -11,9 +11,88 @@ ethlite-contracts - ready-to-use (blockchain) contract services / function call -## Usage +## Usage by Example + +### Contract №1 - PunksMeta (aka CryptoPunksTokenUri) by 0xTycoon + +_The missing tokenURI() for the Punks_ + + +Let's try the `PunksMeta` contract +with the token id 0, that is, punk no. 0: + +``` ruby +require 'ethlite/contracts' + +contract = PunksMeta.new + + +# function parseAttributes(uint256 _tokenId) returns (string[8]) +# +# parseAttributes returns an array of punk attributes. 8 rows in total +# The first row is the Type, and next seven rows are the attributes. +# The values are fetched form the CryptoPunksData contract and then the +# string is parsed. +# @param _tokenId the punk id +ary = contract.parseAttributes( 0 ) +#=> ["Female 2", "Earring", "Blonde Bob", "Green Eye Shadow", "", "", "", + + +# function getAttributes(uint256 _tokenId) returns (string) +# +# getAttributes calls parseAttributes and returns the result as JSON +# @param _tokenId the punk id +str = contract.getAttributes( 0 ) +data = JSON.parse( str ) +#=> [{"trait_type"=>"Type", "value"=>"Female 2"}, +# {"trait_type"=>"Accessory", "value"=>"Earring"}, +# {"trait_type"=>"Accessory", "value"=>"Blonde Bob"}, +# {"trait_type"=>"Accessory", "value"=>"Green Eye Shadow"}] + + +# function tokenURI(uint256 _tokenId) returns (string) +# +# tokenURI gets the metadata about a punk and returns as a JSON +# formatted string, according to the ERC721 schema and market +# recommendations. It also embeds the SVG data. +# The attributes and SVG data are fetched form the CryptoPunksData +# contract, which stores all the CryptoPunks metadata on-chain. +# @param _tokenId the punk id +str = contract.tokenURI( 0 ) +if str.start_with?( 'data:application/json;base64,' ) + str = str.sub( 'data:application/json;base64,', '' ) + ## get metadata (base64-encoded) + data = JSON.parse( Base64.decode64( str ) ) +#=> {"description"=> "CryptoPunks launched as a fixed set of 10,000 items in mid-2017...", +# "external_url"=>"https://cryptopunks.app/cryptopunks/details/0", +# "image"=> "data:image/svg+xml;base64,...", +# "name"=>"CryptoPunk #0", +# "attributes"=> +# [{"trait_type"=>"Type", "value"=>"Female 2"}, +# {"trait_type"=>"Accessory", "value"=>"Earring"}, +# {"trait_type"=>"Accessory", "value"=>"Blonde Bob"}, +# {"trait_type"=>"Accessory", "value"=>"Green Eye Shadow"}]} + + ## get image (base64-encoded) + str_image = data.delete( 'image' ) + str_image = str_image.sub( 'data:image/svg+xml;base64,', '' ) + image = Base64.decode64( str_image ) + ## cut-off inline leading data:image/svg+xml;utf8, too + image = image.sub( 'data:image/svg+xml;utf8,', '' ) + + write_json( "punksmeta/punk0.json", data ) + write_text( "punksmeta/punk0.svg", image ) + else + puts "!! ERROR - expected json base64-encoded; got:" + pp str + exit 1 + end +end +``` + +Note: See [`punksmeta/punk0.json`](punksmeta/punk0.json) +and [`punksmeta/punk0.svg`](punksmeta/punk0.svg) for the saved copies of the data. -To be done diff --git a/ethlite-contracts/punksmeta/punk0.json b/ethlite-contracts/punksmeta/punk0.json new file mode 100644 index 0000000..c1b7079 --- /dev/null +++ b/ethlite-contracts/punksmeta/punk0.json @@ -0,0 +1,23 @@ +{ + "description": "CryptoPunks launched as a fixed set of 10,000 items in mid-2017 and became one of the inspirations for the ERC-721 standard. They have been featured in places like The New York Times, Christie's of London, Art|Basel Miami, and The PBS NewsHour.", + "external_url": "https://cryptopunks.app/cryptopunks/details/0", + "name": "CryptoPunk #0", + "attributes": [ + { + "trait_type": "Type", + "value": "Female 2" + }, + { + "trait_type": "Accessory", + "value": "Earring" + }, + { + "trait_type": "Accessory", + "value": "Blonde Bob" + }, + { + "trait_type": "Accessory", + "value": "Green Eye Shadow" + } + ] +} \ No newline at end of file diff --git a/ethlite-contracts/punksmeta/punk0.svg b/ethlite-contracts/punksmeta/punk0.svg new file mode 100644 index 0000000..dcd0f4c --- /dev/null +++ b/ethlite-contracts/punksmeta/punk0.svg @@ -0,0 +1 @@ + \ No newline at end of file