--- a/pallets/nft/src/eth/erc.rs +++ b/pallets/nft/src/eth/erc.rs @@ -2,7 +2,6 @@ use evm_coder::{ToLog, execution::Result, solidity, solidity_interface, types::*}; use nft_data_structs::{CreateItemData, CreateNftData}; use core::convert::TryInto; -use alloc::format; use crate::{ Allowances, Module, Balance, CollectionHandle, CollectionMode, Config, NftItemList, ItemListIndex, @@ -46,9 +45,15 @@ #[solidity_interface(name = "ERC721Metadata", inline_is(InlineNameSymbol))] impl CollectionHandle { + #[solidity(rename_selector = "tokenURI")] fn token_uri(&self, token_id: uint256) -> Result { - // TODO: We should standartize url prefix, maybe via offchain schema? - Ok(format!("unique.network/{}/{}", self.id, token_id)) + let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?; + Ok(string::from_utf8_lossy( + &>::get(self.id, token_id) + .ok_or("token not found")? + .const_data, + ) + .into()) } } --- a/pallets/nft/src/eth/stubs/ERC721.sol +++ b/pallets/nft/src/eth/stubs/ERC721.sol @@ -140,7 +140,7 @@ } contract ERC721Metadata is Dummy, InlineNameSymbol { - function tokenUri(uint256 tokenId) public view returns (string memory) { + function tokenURI(uint256 tokenId) public view returns (string memory) { require(false, stub_error); tokenId; dummy;