The Token Name Service v3 uses The Graph for efficient data querying. The endpoint for accessing data is query.graph.tkn.xyz/subgraphs/name/tkn/v3. Additionally, the contract data is stored on Data Chain and can be accessed through a proxy contract.
GraphQL Queries
Get Token Information by Symbol
Retrieve detailed information about a token using its symbol.
{ tokens(where: { symbol: "WETH" }) { id name description symbol avatar dweb discord decimals addresses { tokenAddress chainID { id } } }}
This query returns:
Basic token information (name, symbol, description)
Media assets (avatar, dweb)
Social links (discord)
Technical details (decimals)
Contract addresses across different chains
constquery=`{ tokens(where: { symbol: "WETH" }) { id name description symbol avatar dweb discord decimals addresses { tokenAddress chainID { id } } }}`;constresponse=awaitfetch('https://query.graph.tkn.xyz/subgraphs/name/tkn/v3', { method:'POST', headers: {'Content-Type':'application/json', }, body:JSON.stringify({ query }),});constdata=awaitresponse.json();
Get Token Information by Contract Address
Look up token information using a contract address.
queryTokenByAddress { addresses(where: {tokenAddress: "0x5979D7b546E38E414F7E9822514be443A4800529"}) { addressID chainID { id } tokenAddress nonEVMAddress id tokenID { avatar description decimals name symbol tokenSupply twitter } }}
This query returns:
Chain information
Token address details (EVM and non-EVM)
Associated token metadata
Social media links
constquery=` query TokenByAddress { addresses(where: {tokenAddress: "0x5979D7b546E38E414F7E9822514be443A4800529"}) { addressID chainID { id } tokenAddress nonEVMAddress id tokenID { avatar description decimals name symbol tokenSupply twitter } } }`;constresponse=awaitfetch('https://query.graph.tkn.xyz/subgraphs/name/tkn/v3', { method:'POST', headers: {'Content-Type':'application/json', }, body:JSON.stringify({ query }),});constdata=awaitresponse.json();
constabi= [/* See full ABI in repository */];constcontractAddress="0x7b02d739D95758F09dDc7e44FA951cd45D97247A";constcontract=newethers.Contract(contractAddress, abi, provider);// Get token ID by symbolconsttokenId=awaitcontract.getTokenIdBySymbol("WETH");// Get token dataconsttokenName=awaitcontract.getTokenData(tokenId,"name");consttokenDescription=awaitcontract.getTokenData(tokenId,"description");consttokenDecimals=awaitcontract.getTokenData(tokenId,"decimals");// Get token address for a specific chainconstaddressInfo=awaitcontract.getAddressBySymbolAndChain("WETH","1"); // chainId 1 for Ethereum mainnet
constcontractAddress="0x7b02d739D95758F09dDc7e44FA951cd45D97247A";constcontract=newweb3.eth.Contract(abi, contractAddress);// Get token ID by symbolconsttokenId=awaitcontract.methods.getTokenIdBySymbol("WETH").call();// Get token dataconsttokenName=awaitcontract.methods.getTokenData(tokenId,"name").call();consttokenDescription=awaitcontract.methods.getTokenData(tokenId,"description").call();consttokenDecimals=awaitcontract.methods.getTokenData(tokenId,"decimals").call();// Get token address for a specific chainconstaddressInfo=awaitcontract.methods.getAddressBySymbolAndChain("WETH","1").call();