githubEdit

Querying the Dataset

Overview

The Token Name Service uses ENSarrow-up-right, and can be queried anywhere .eth domains are supported

The Token name set is persisted as subdomains of the .tkn.eth domain

For instance, the contract for USDC can be found at usdc.tkn.etharrow-up-right and Wrapped Bitcoin at wbtc.tkn.etharrow-up-right

Descriptive metadata can be found on chain in each token's ENS resolver. Including name, description, avatar, url, dweb, decimals, notice, version, twitter, & github.

The TNS.sol contract exposes additional queries; such as: fetch all metadata, fetch token contracts on all chains, and token balance for address. TNS.sol is hosted at tkn.etharrow-up-right

Get token contract address

Retrieves the address where the token contract resides.

Useful for converting a user supplied token symbol into an actionable contract.

await provider.resolveName("uni.tkn.eth");
// '0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984'

Get token by contract address

Reverse resolution by token contract address is now available

Query <tokenAddress>.<chain>.tkn.eth to fetch the metadata for that token

Example: 0x78b3C724A2F663D11373C4a1978689271895256f.base.tkn.etharrow-up-right ($TKN on Base) will resolve the data for the $TKN token

Get single datapoint

Get one of the datapoints available for each token.

Pulls a single datapoint, such as a name or description.

To see the available data types visit: https://docs.tkn.xyz/developers/datasetarrow-up-right

Get all token info

Retrieve all datapoints for a token, excluding the sidechain contract addresses.

Useful for fetching all token data in a single query.

Get all token info and sidechain contract addresses

Retrieve all token info and it's sidechain contract addresses.

Useful for fetching all known data about a token in a single query.

Decoding non-EVM and dweb responses: Non-EVM contract addresses can be decoded with https://www.npmjs.com/package/@ensdomains/address-encoderarrow-up-right addressEncoder.formatsByName['SOL'].encoder(Buffer.from(tokenData.sol_address.substring(2), 'hex')) And the dweb IPFS CID can be decoded with https://github.com/pldespaigne/content-hash#contenthashdecode-contenthash----stringarrow-up-right

Get all sidechain contract addresses

Retrieve all token sidechain contract addresses.

Useful for a token's contract addresses for all chains in a single query.

Decoding non-EVM contract addresses: Non-EVM contract addresses can be decoded with https://www.npmjs.com/package/@ensdomains/address-encoderarrow-up-right addressEncoder.formatsByName['SOL'].encoder(Buffer.from(tokenData.sol_address.substring(2), 'hex'))

Get tokens owned by an address

Lookup how many tokens an address owns, using a token symbol.

Helpful for looking up an ERC20 account balance without having to fetch the token contract address separately.

Get all TKN tokens

There are multiple ways to fetch the complete list of tokens

  1. Registry.tkn.eth: a simple JSON array with the symbols for all listed tokens. The current source of truth for TKN listings. Can be fetched with an IPFS dweb resolver, or eth.limo. https://registry.tkn.eth.limo/arrow-up-right

  2. TheGraph: TKN now has it's very own subgraph. Can conveniently produce all tokens and metadata in a single query.

Use this TKN Subgraph query to fetch all tokens and metadata at once:

And this query can be used to fetch a single token:

  1. TokenList: Tokenlists.org formatted list. Published at list.tkn.eth. View at: https://tokenlists.org/token-list?url=list.tkn.etharrow-up-right

Last updated

Was this helpful?