Metadata Implementation
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
1
//Get my favorite object Id
2
var objectId = configuration.myObjectId;
3
4
//Call the uri(uint256) method of the collection passing the desired objectId
5
var tokenUri = await collection.contract.methods.uri(objectId).call();
6
7
//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 it
8
tokenUri = "https://gateway.ipfs.io/ipfs/" + tokenUri.split('ipfs://ipfs/')[0];
9
10
//Get the JSON
11
var itemMetadata = JSON.parse(await(await fetch(tokenUri)).text());
12
13
//Let's save it into the original item
14
var originalItem = collection.items.filter(it => it.objectId === objectId)[0];
15
originalItem.metadata = itemMetadata;
16
17
//You can now navigate in all the properties of the itemMetadata object
Copied!
How to find an ERC20 token address
1
//Suppose you have the address of the Interoperational Interface wrapping your favorite ERC20 token
2
var myFavoriteWrappedERC20TokenInteroperationalInterfaceAddress = configuration.myFavoriteWrappedERC20TokenInteroperationalInterfaceAddress;
3
4
//Let's retrieve the Smart Contract
5
var myFavoriteWrappedERC20TokenInteroperationalInterface = new web3.eth.Contract(configuration.IEthItemInteroperationalInterfaceABI, myFavoriteWrappedERC20TokenInteroperationalInterfaceAddress);
6
7
//Let's now retrieve the corresponding Object Id
8
var objectId = myFavoriteWrappedERC20TokenInteroperationalInterface.methods.objectId().call();
9
10
//Call the Orchestrator and then the KnowledgeBase to retrieve the last ERC20Wrapper ITEM
11
var knowledgeBase = new web3.eth.Contract(configuration.EthItemKnowledgeBaseABI , await ethItemOrchestrator.knowledgeBase().call());
12
var collectionAddress = await knowledgeBase.methods.erc20Wrapper().call();
13
14
//Normalize the address for eventual search by address purposes
15
collectionAddress = web3.utils.toChecksumAddress(collectionAddress);
16
17
//Collection category to distinguish all collection types, "W20" means that this Collection is a Wrapper of ERC20 Tokens
18
var collectionCategory = "W20";
19
20
var collectionABI = configuration.W20ABI;
21
22
//The needed basic info to operate are of course the Collection address, category and Smart Contract. They can be of course enriched
23
var collection = {
24
address : collectionAddress,
25
category : collectionCategory,
26
contract : new web3.eth.Contract(collectionABI, collectionAddress)
27
};
28
29
//Now we can retrieve the original ERC20TokenAddress through the collection
30
var originalERC20Address = await collection.methods.source(objectId);
31
32
//Now you can use it in combination with your favorite repository to obtain the logo URI or whatever
Copied!
Copy link