Metadata is a standard used in the ERC721 and ERC1155 ecosystems to express a token’s real information based on how creators manage the tokenUri link. In the ERC20 ecosystem, the most used info sources are the Etherscan servers and the Trust Wallet repo. Whenever you see a token logo on famous dApps, for example, you're trusting the Trust Wallet repo on GitHub.
Fun fact: Token creators must pay Trust Wallet 1 BNB to add/edit their token logo/info.
Using the ITEM standard, every token has a tokenUri with all of the official information needed to build a frontend without needing to deal with third parties. The most important benefit to security here is that the right to update the tokenURI of a token is with the owner. If the owner is a wallet, they fully control this info. If the owner is an on-chain org, or a smart contract with custom functionalities, the metadata can be upgraded directly via voting or other specific functions. No ITEM token owner has to rely on assumptions about third-party security.
Call TokenUri
//Get my favorite object Idvar objectId =configuration.myObjectId;//Call the uri(uint256) method of the collection passing the desired objectIdvar tokenUri =awaitcollection.contract.methods.uri(objectId).call();//To keep compatibility with applications like OnpenSea, the tokenUri must start with ipfs://ipfs/... which is actually not readable from browsers. So let's replace ittokenUri ="https://gateway.ipfs.io/ipfs/"+tokenUri.split('ipfs://ipfs/')[0];//Get the JSONvar itemMetadata =JSON.parse(await(awaitfetch(tokenUri)).text());//Let's save it into the original itemvar originalItem =collection.items.filter(it =>it.objectId === objectId)[0];originalItem.metadata = itemMetadata;//You can now navigate in all the properties of the itemMetadata object
How to find an ERC20 token address
//Suppose you have the address of the Interoperational Interface wrapping your favorite ERC20 tokenvar myFavoriteWrappedERC20TokenInteroperationalInterfaceAddress =configuration.myFavoriteWrappedERC20TokenInteroperationalInterfaceAddress;//Let's retrieve the Smart Contractvar myFavoriteWrappedERC20TokenInteroperationalInterface =newweb3.eth.Contract(configuration.IEthItemInteroperationalInterfaceABI, myFavoriteWrappedERC20TokenInteroperationalInterfaceAddress);//Let's now retrieve the corresponding Object Idvar objectId =myFavoriteWrappedERC20TokenInteroperationalInterface.methods.objectId().call();//Call the Orchestrator and then the KnowledgeBase to retrieve the last ERC20Wrapper ITEMvar knowledgeBase =newweb3.eth.Contract(configuration.EthItemKnowledgeBaseABI ,awaitethItemOrchestrator.knowledgeBase().call());var collectionAddress =awaitknowledgeBase.methods.erc20Wrapper().call();//Normalize the address for eventual search by address purposescollectionAddress =web3.utils.toChecksumAddress(collectionAddress);//Collection category to distinguish all collection types, "W20" means that this Collection is a Wrapper of ERC20 Tokensvar collectionCategory ="W20";var collectionABI =configuration.W20ABI;//The needed basic info to operate are of course the Collection address, category and Smart Contract. They can be of course enrichedvar collection = { address : collectionAddress, category : collectionCategory, contract :newweb3.eth.Contract(collectionABI, collectionAddress)};//Now we can retrieve the original ERC20TokenAddress through the collectionvar originalERC20Address =awaitcollection.methods.source(objectId);//Now you can use it in combination with your favorite repository to obtain the logo URI or whatever