Create an instance of TokenService
Optional
chainId: number{number} the chainId number. defaults to getCurrentChain()
get the contract address of the native token
// should always return:
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
get supported chain map
const supportedChainMap : RpcSupportedChainMap = new TokenService( 1 ).getSupportedChainMap();
// should return:
{
1 : "mainnet", // Ethereum mainnet
42161 : "arb1", // Arbitrum One
1313161554 : "aurora", // Aurora Mainnet
43114 : "avax", // Avalanche C-Chain, token : AVAX
8453 : "base", // Base
56 : "bnb", // BNB Smart Chain Mainnet
324 : "zksync", // zkSync Era Mainnet
250 : "ftm", // Fantom Opera
100 : "gno", // Gnosis
8217 : "cypress", // Klaytn Mainnet Cypress
10 : "oeth", // OP Mainnet
137 : "matic", // Polygon Mainnet
}
get supported chain id list
get supported chain/network short name list
get token item
{string} contract address
//
// switch chain/network to BNB Smart Chain Mainnet
//
const currentChainId = 56;
const contractAddress : string = new TokenService( currentChainId ).nativeTokenAddress;
const item = await new TokenService( currentChainId ).getItem( contractAddress );
// should return:
{
chainId: 56,
symbol: 'BNB',
name: 'BNB',
address: '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
decimals: 18,
logoURI: 'https://tokens.1inch.io/0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c.png',
providers: [ '1inch', 'Curve Token List' ],
eip2612: false,
tags: [ 'native' ]
}
get the decimals value of a token
{string} contract address
//
// switch chain/network to Ethereum Mainnet
//
const currentChainId = 1;
// contract address of ETH
const contractAddress : string = new TokenService( currentChainId ).nativeTokenAddress;
const decimals = await new TokenService( currentChainId ).getItemDecimals( contractAddress );
// should return:
18
//
// switch chain/network to Ethereum Mainnet
//
const currentChainId = 1;
// contract address of Tether USD
const contractAddress : string = `0xdac17f958d2ee523a2206206994597c13d831ec7`;
const decimals = await new TokenService( currentChainId ).getItemDecimals( contractAddress );
// should return:
6
get the logo url of a token
{string} contract address
//
// switch chain/network to Ethereum Mainnet
//
const currentChainId = 1;
const contractAddress : string = new TokenService( currentChainId ).nativeTokenAddress;
const logoUrl = await new TokenService( currentChainId ).getItemLogo( contractAddress );
// should return:
{
oneInch : "https://tokens.1inch.io/0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.png",
metaBeem : "https://tokens.metabeem.io/0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.png",
base64 : "data:image/png;base64,UklGRlYLAABXRUJQVlA4TEkLAAAv/8A/EC8FoW0kQZKnD8Dzh3p/Mx0aENpIkiS5ZjEcf5hvTYWDt...",
}
The class constructor needs to pass in a chainId. Before you create an instance, you can get the currently supported chainId list in the following way: