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)
const abi = [/* See full ABI in repository */];
const contractAddress = "0x7b02d739D95758F09dDc7e44FA951cd45D97247A";
const contract = new ethers.Contract(contractAddress, abi, provider);
// Get token ID by symbol
const tokenId = await contract.getTokenIdBySymbol("WETH");
// Get token data
const tokenName = await contract.getTokenData(tokenId, "name");
const tokenDescription = await contract.getTokenData(tokenId, "description");
const tokenDecimals = await contract.getTokenData(tokenId, "decimals");
// Get token address for a specific chain
const addressInfo = await contract.getAddressBySymbolAndChain("WETH", "1"); // chainId 1 for Ethereum mainnet
const contractAddress = "0x7b02d739D95758F09dDc7e44FA951cd45D97247A";
const contract = new web3.eth.Contract(abi, contractAddress);
// Get token ID by symbol
const tokenId = await contract.methods.getTokenIdBySymbol("WETH").call();
// Get token data
const tokenName = await contract.methods.getTokenData(tokenId, "name").call();
const tokenDescription = await contract.methods.getTokenData(tokenId, "description").call();
const tokenDecimals = await contract.methods.getTokenData(tokenId, "decimals").call();
// Get token address for a specific chain
const addressInfo = await contract.methods.getAddressBySymbolAndChain("WETH", "1").call();