Type/to search
Built-in Functions
Structures
Built-in Variables and Constants
Conventions
Exchanges
Capability Matrix
Centralized Exchanges
Decentralized Exchanges (DEX)
Prediction Markets
Securities and Futures
On-chain & Custom

Registers a token, or lists the token table; a registered token can be used by name in trading pairs.

exchange.IO(k)
exchange.IO(k, name, address)

Examples

Register UNI on Ethereum and query the UNI_USDC ticker (contract addresses differ per chain; use the address on your chain).

javascript
function main() { var t = exchange.IO("token", "UNI", "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984") if (!t) { Log("Registration failed:", GetLastError()) return } var ticker = exchange.GetTicker("UNI_USDC") Log(t.symbol, "decimals:", t.decimals, "bid:", ticker.Buy, "ask:", ticker.Sell) }

Returns

TypeDescription

object / array / null value

When a token is registered, the function returns {symbol, address, decimals}. When no arguments are passed, it returns the token table as an array, and each item is {symbol, address, decimals, native}. If native is true, the token is the chain's native coin. If the address is not an ERC20 token, the function returns null.

Arguments

NameTypeRequiredDescription

k

string

Yes

Set to token, which means a token is being registered.

name

string

No

The name the token uses in trading pairs, such as UNI.

address

string

No

The token's contract address. Its decimals are read from the chain.

See Also

Remarks

Token names are resolved in this order: ① The token table. It holds manually verified built-in tokens (the native coin, the wrapped coin, USDC, USDT, the chain's BTC, and others) and any tokens registered with exchange.IO("token", ...). If a registered token has the same name as a built-in token, it replaces that built-in entry. ② The official token lists. The lists depend on the chain, not on the exchange (KyberSwap and 1inch exchange objects use the same lists on the same chain): BNB Chain merges the PancakeSwap list (tokens.pancakeswap.finance) with the Uniswap Labs default list (tokens.uniswap.org), Base merges the Uniswap Labs list with the PancakeSwap list, and the other chains use the Uniswap Labs list. Tokens resolved from an official list are added to the token table. The connector ships with a snapshot of these lists. It fetches the latest lists only when a name is not in the snapshot, and it fetches them at most once every 24 hours.

If an official list has more than one token with the same name on the same chain, such as a bridged version and a native version, you cannot use that name directly. The error message lists the candidate addresses, so specify the token by its contract address instead. The decimals of a listed token are taken from its on-chain contract. If they differ from the list's record, the token is rejected.

A token that is not in the token table can still be used in a trading pair through its contract address, for example 0x1f9840a85d5af5bf1d1762f925bdaddc4201f984_USDC.

exchange.GetMarkets() lists only two kinds of trading pairs: pairs between tokens in the token table (built-in and registered tokens), and pairs of popular high-liquidity coins against the wrapped coin, USDC, or USDT. Tokens that are not listed can still be traded directly.

A native coin (such as ETH or BNB) and its wrapped coin (such as WETH or WBNB) are two different assets. When you trade the native coin, the router contract wraps and unwraps it automatically.