Etherscan

OpenSea 如何獲取 Town Star ERC1155 令牌圖像?

  • January 14, 2022

我發現Town Star ERC1155 token ABI的合約沒有uri功能

我嘗試使用 OpenSea API 來檢查我選擇This one的隨機令牌的元數據。

API呼叫https://api.opensea.io/api/v1/assets?asset_contract_address=0xc36cf0cfcb5d905b8b513860db0cfe63f6cf9f5c&token_ids=122161369724616908383351484068004787912704響應如下:

{"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}]}

還有一個重點token_metadata節目https://tokens.gala.games/sandbox-games/town-star/skins/mirandus-fabric-plant-skin.json

元數據包含令牌的圖像 uri ( https://tokens.gala.games/images/sandbox-games/town-star/skins/mirandus-fabric-plant-skin.png )

但是……由於 ABI 沒有uri功能,OpenSea 如何獲取元數據 uri(https://tokens.gala.games/sandbox-games/town-star/skins/mirandus-fabric-plant-skin.json)?

有趣的問題!

Town Star 代幣是 ERC1155 代幣。該tokenURI屬性是 ERC20 代幣規範的一部分。因此,您不會在 Town Star 的契約中找到它。根據文件,ERC1155 的版本tokenURI被呼叫IERC1155MetadataURI並且是完全可選的。

但是,Town Star 確實在不同的位置包含 URI。如果你在 etherscan 上查看合約,create函式看起來像這樣。

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;
   }

您可以看到 create 函式在_uri參數中接收一個 URI,但它沒有儲存它,而是發出一個事件 - URI。事件 URI 在合約中有如下定義。

event URI(string _value, uint256 indexed _id);

這個topic_0函式的 是0x6bb7ff708619ba0610cba295a58592e0451dee2622938c8755667688daf3529b。如果您使用 this 在 etherscan 中搜尋日誌topic_0,您將能夠看到所有發出的事件,從而看到所有令牌 URI。我正在添加一個螢幕截圖以供參考。

Town Star合約URI事件日誌截圖

事件也可以用作 EVM 區塊鏈中的廉價儲存。它比儲存成本低。Town Star 的開發人員決定使用事件來儲存 URI。

希望這能澄清你的問題。

引用自:https://ethereum.stackexchange.com/questions/118925