0

I find that contract of Town Star ERC1155 token ABI does not have uri function code

And I try to use OpenSea API to check a metadate for a random token I choose This one.

API call https://api.opensea.io/api/v1/assets?asset_contract_address=0xc36cf0cfcb5d905b8b513860db0cfe63f6cf9f5c&token_ids=122161369724616908383351484068004787912704 response as below:

{"assets":[{"id":29329471,"token_id":"122161369724616908383351484068004787912704","num_sales":56,"background_color":null,"image_url":"https://lh3.googleusercontent.com/sFXH5WPo8nACwhdrtbSBHqvondVjWUJ-pWxacKwOIPF36J_2ZIGgVSuMSi3yqJY15UpdRbPMjEYV93fYXfCNqiDyguUgf2SFQny8UCA","image_preview_url":"https://lh3.googleusercontent.com/sFXH5WPo8nACwhdrtbSBHqvondVjWUJ-pWxacKwOIPF36J_2ZIGgVSuMSi3yqJY15UpdRbPMjEYV93fYXfCNqiDyguUgf2SFQny8UCA=s250","image_thumbnail_url":"https://lh3.googleusercontent.com/sFXH5WPo8nACwhdrtbSBHqvondVjWUJ-pWxacKwOIPF36J_2ZIGgVSuMSi3yqJY15UpdRbPMjEYV93fYXfCNqiDyguUgf2SFQny8UCA=s128","image_original_url":"https://tokens.gala.games/images/sandbox-games/town-star/skins/mirandus-fabric-plant-skin.png","animation_url":null,"animation_original_url":null,"name":"Mirandus Fabric Plant Skin","description":"Changes the look of your Fabric Plant to be Mirandus themed!","external_link":null,"asset_contract":{"address":"0xc36cf0cfcb5d905b8b513860db0cfe63f6cf9f5c","asset_contract_type":"semi-fungible","created_date":"2020-06-15T19:18:12.470039","name":"Gala Games","nft_version":null,"opensea_version":null,"owner":7360995,"schema_name":"ERC1155","symbol":"","total_supply":null,"description":"From one of the founders of Zynga and some of the creative minds behind FarmVille and Words With Friends comes Town Star. Blockchain is the next evolution of gaming and has the $148B industry buzzing with excitement. It’s gaming re-imagined to benefit creators and players, alike.","external_link":"https://www.gala.games/","image_url":"https://lh3.googleusercontent.com/wp7V1K4Ezhi8yHU6LFpff-GMsjend65nRiwNz5pGAjCwk7ybznEpfUvXiIxQoOWBmeN00AGjVTRhLUqY4fee1fus=s120","default_to_fiat":false,"dev_buyer_fee_basis_points":0,"dev_seller_fee_basis_points":250,"only_proxied_transfers":false,"opensea_buyer_fee_basis_points":0,"opensea_seller_fee_basis_points":250,"buyer_fee_basis_points":0,"seller_fee_basis_points":500,"payout_address":"0xa92abb0d0dd1e8e73006fc3b6229b7bd9e0d5c61"},"permalink":"https://opensea.io/assets/0xc36cf0cfcb5d905b8b513860db0cfe63f6cf9f5c/122161369724616908383351484068004787912704","collection":{"banner_image_url":null,"chat_url":null,"created_date":"2020-07-07T04:21:17.383133","default_to_fiat":false,"description":"From one of the founders of Zynga and some of the creative minds behind FarmVille and Words With Friends comes Town Star. Blockchain is the next evolution of gaming and has the $148B industry buzzing with excitement. It’s gaming re-imagined to benefit creators and players, alike.","dev_buyer_fee_basis_points":"0","dev_seller_fee_basis_points":"250","discord_url":null,"display_data":{"card_display_style":"padded"},"external_url":"https://www.gala.games/","featured":false,"featured_image_url":null,"hidden":false,"safelist_request_status":"verified","image_url":"https://lh3.googleusercontent.com/wp7V1K4Ezhi8yHU6LFpff-GMsjend65nRiwNz5pGAjCwk7ybznEpfUvXiIxQoOWBmeN00AGjVTRhLUqY4fee1fus=s120","is_subject_to_whitelist":false,"large_image_url":"https://lh3.googleusercontent.com/wp7V1K4Ezhi8yHU6LFpff-GMsjend65nRiwNz5pGAjCwk7ybznEpfUvXiIxQoOWBmeN00AGjVTRhLUqY4fee1fus","medium_username":"GoGalaGames","name":"Town Star","only_proxied_transfers":false,"opensea_buyer_fee_basis_points":"0","opensea_seller_fee_basis_points":"250","payout_address":"0xa92abb0d0dd1e8e73006fc3b6229b7bd9e0d5c61","require_email":false,"short_description":null,"slug":"town-star","telegram_url":"https://t.me/GoGalaGames","twitter_username":"GoGalaGames","instagram_username":null,"wiki_url":null},"decimals":null,"token_metadata":"https://tokens.gala.games/sandbox-games/town-star/skins/mirandus-fabric-plant-skin.json","owner":{"user":{"username":"NullAddress"},"profile_img_url":"https://storage.googleapis.com/opensea-static/opensea-profile/1.png","address":"0x0000000000000000000000000000000000000000","config":""},"sell_orders":[{"created_date":"2022-01-11T05:48:40.269327","closing_date":"2022-07-11T05:48:15","closing_extendable":false,"expiration_time":1657518495,"listing_time":1641880003,"order_hash":"0xbf2c9369b948b835232088755d96bb66ef2edea01d13b42428dae3e242078c75","metadata":{"asset":{"id":"122161369724616908383351484068004787912704","address":"0xc36cf0cfcb5d905b8b513860db0cfe63f6cf9f5c","quantity":"1"},"schema":"ERC1155"},"exchange":"0x7be8076f4ea4a4ad08075c2508e481d6c946d12b","maker":{"user":11403466,"profile_img_url":"https://storage.googleapis.com/opensea-static/opensea-profile/26.png","address":"0x1c50bb18b4ec35103bccc10b76e9afdb289b975a","config":""},"taker":{"user":1766,"profile_img_url":"https://storage.googleapis.com/opensea-static/opensea-profile/1.png","address":"0x0000000000000000000000000000000000000000","config":""},"current_price":"3796000000.000000000000000000","current_bounty":"37960000","bounty_multiple":"0.01","maker_relayer_fee":"500","taker_relayer_fee":"0","maker_protocol_fee":"0","taker_protocol_fee":"0","maker_referrer_fee":"0","fee_recipient":{"user":3585,"profile_img_url":"https://storage.googleapis.com/opensea-static/opensea-profile/28.png","address":"0x5b3256965e7c3cf26e11fcaf296dfc8807c01073","config":"verified"},"fee_method":1,"side":1,"sale_kind":0,"target":"0xc36cf0cfcb5d905b8b513860db0cfe63f6cf9f5c","how_to_call":0,"calldata":"0xf242432a0000000000000000000000001c50bb18b4ec35103bccc10b76e9afdb289b975a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000","replacement_pattern":"0x000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","static_target":"0x0000000000000000000000000000000000000000","static_extradata":"0x","payment_token":"0x15d4c048f83bd7e37d49ea4c83a07267ec4203da","payment_token_contract":{"id":318,"symbol":"GALA","address":"0x15d4c048f83bd7e37d49ea4c83a07267ec4203da","image_url":"https://lh3.googleusercontent.com/1DcP21E8JYH0YEvBF9HD2R4LrK742KQGJyumV5kJkAxRp2wEdOcQrvsVJmUIaNJMVkFKyxSMLZRVA-sBGfCnoEDD=s120","name":"Gala","decimals":8,"eth_price":"0.000100560000000","usd_price":"0.327482000000000000"},"base_price":"3796000000","extra":"0","quantity":"1","salt":"13486021474025852519810271922175260653938170746936005350352089145218669257494","v":28,"r":"0x05539ff3074fc24fd81605aed846a6636aa4c841f7c75ac27a5b6900f2c396c2","s":"0x4dc37f0182ccf337bfca2a91d759f061dbe57353c69100f95f22f20dec821eb5","approved_on_chain":false,"cancelled":false,"finalized":false,"marked_invalid":false,"prefixed_hash":"0x0137d05a6d560944002aad2be4cfbaa91f71a38308894d032314e8e589da572d"}],"creator":{"user":null,"profile_img_url":"https://storage.googleapis.com/opensea-static/opensea-profile/17.png","address":"0x0d24de9dccd263b310b7809283786c58d1f6a667","config":""},"traits":[{"trait_type":"game","value":"Town Star","display_type":null,"max_value":null,"trait_count":239,"order":null},{"trait_type":"category","value":"Skins","display_type":null,"max_value":null,"trait_count":71,"order":null},{"trait_type":"tokenRun","value":"skins","display_type":null,"max_value":null,"trait_count":71,"order":null}],"last_sale":{"asset":{"token_id":"122161369724616908383351484068004787912704","decimals":null},"asset_bundle":null,"event_type":"successful","event_timestamp":"2022-01-13T20:21:09","auction_type":null,"total_price":"41400000000000000","payment_token":{"id":1,"symbol":"ETH","address":"0x0000000000000000000000000000000000000000","image_url":"https://storage.opensea.io/files/6f8e2979d428180222796ff4a33ab929.svg","name":"Ether","decimals":18,"eth_price":"1.000000000000000","usd_price":"3266.159999999999854000"},"transaction":{"block_hash":"0x527bc881a7162b949d7dfad15b37b852cf92cd99b613dde02afb8acdf1ab3a79","block_number":"13999276","from_account":{"user":{"username":null},"profile_img_url":"https://storage.googleapis.com/opensea-static/opensea-profile/9.png","address":"0x0ddb92119f32ae8b49b4143e404d023edbc4a5c8","config":""},"id":247299588,"timestamp":"2022-01-13T20:21:09","to_account":{"user":{"username":"OpenSea-Orders"},"profile_img_url":"https://storage.googleapis.com/opensea-static/opensea-profile/22.png","address":"0x7be8076f4ea4a4ad08075c2508e481d6c946d12b","config":"verified"},"transaction_hash":"0xb53a5518d0a0b8aabfe7f1945cfdc77f05d5f71e15a73cba683143e2cbaf1efc","transaction_index":"25"},"created_date":"2022-01-13T20:21:25.825679","quantity":"6"},"top_bid":null,"listing_date":null,"is_presale":false,"transfer_fee_payment_token":null,"transfer_fee":null}]}

And there has a key token_metadata shows https://tokens.gala.games/sandbox-games/town-star/skins/mirandus-fabric-plant-skin.json

The metadata contain image uri for token (https://tokens.gala.games/images/sandbox-games/town-star/skins/mirandus-fabric-plant-skin.png)

But... since ABI does not have uri function, how does OpenSea get that metadata uri (https://tokens.gala.games/sandbox-games/town-star/skins/mirandus-fabric-plant-skin.json)?

1 Answer 1

2

Interesting question!

Town Star token is an ERC1155 token. The tokenURI property is part of the ERC20 token specification. Hence, you won't find it in Town Star's contract. According to the docs, ERC1155's version of tokenURI is called IERC1155MetadataURI and is totally optional.

However, Town Star does contain the URI in a different place. If you look at the contract on etherscan, the create function looks like this.

function create(string calldata _uri, bool _isNF) external creatorOnly returns (uint256 _type) {

        _type = (++nonce << 128);
        if (_isNF) _type = _type | TYPE_NF_BIT;
        emit TransferSingle(msg.sender, address(0x0), address(0x0), _type, 0);


        if (bytes(_uri).length > 0) emit URI(_uri, _type);
        // the above line emits an event
  
        return _type;
    }

You can see that the create function takes in a URI in _uri parameter, but instead of storing it, it emits an event - URI. The event URI has the following definition in the contract.

event URI(string _value, uint256 indexed _id);

The topic_0 of this function is 0x6bb7ff708619ba0610cba295a58592e0451dee2622938c8755667688daf3529b. If you search the logs in etherscan with this topic_0, you'll be able to see all the events emitted, thus all the token URI. I'm adding a screenshot for reference.

Screenshot of logs of URI events of Town Star contract

Events can also be used as cheap storage in the EVM blockchains. It costs less gas than storage. The devs of Town Star have decided to use events to store the URI.

Hope this clarifies your question.

2
  • So, does it means that OpenSean need to parse events logs and get least event value to get metadata? Like this
    – niw
    Jan 15 at 8:53
  • I need at least 15 reputation to cast a vote...😅
    – niw
    Jan 15 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.