exchange.IO("contracts", ...)
Obtains commonly used contract addresses on the current chain (or a specified chain), including mainstream tokens, Multicall3, Permit2, as well as the Factory, router, QuoterV2, and position manager contracts of Uniswap V3 and PancakeSwap V3.
exchange.IO(k)
exchange.IO(k, chainId)Examples
View the commonly used contract addresses of the current chain and use QuoterV2 to get a quote.
javascript
function main() {
// Get the commonly used contract address table of the current chain
var C = exchange.IO("contracts")
Log(C.name, "chainId:", C.chainId, "Wrapped native token:", C.wrappedNative)
for (var sym in C.tokens) {
Log(sym, C.tokens[sym].address, "decimals:", C.tokens[sym].decimals)
}
Log("Uniswap V3:", JSON.stringify(C.uniswapV3))
// Use the addresses in the address table and the built-in ABI template to get a quote
var quoter = C.uniswapV3.quoterV2
exchange.IO("abi", quoter, "uniswapV3QuoterV2")
var q = exchange.IO("call", quoter, "quoteExactInputSingle",
[C.tokens.WETH.address, C.tokens.USDC.address, exchange.IO("toUnits", "1", 18), 500, 0])
Log("1 WETH ≈", exchange.IO("fromUnits", q.amountOut, 6), "USDC")
// View the address table of another chain
Log("BSC PancakeSwap V3:", JSON.stringify(exchange.IO("contracts", 56).pancakeV3))
}Returns
| Type | Description |
object | Returns |
Arguments
| Name | Type | Required | Description |
k | string | Yes | Functionality of the |
chainId | number | No | Chain ID. If not passed, the chain of the current node is used by default. Currently supported chains: Ethereum (1), BNB Smart Chain (56), Base (8453), Arbitrum One (42161). |
See Also
Web3 exchange.IO exchange.IO("api") exchange.IO("multicall") exchange.IO("uniswapV3") exchange.IO("abi")
Remarks
Every address in the address table has been verified on-chain: the contract code exists; the symbol and decimals of each token are consistent with the on-chain query results; the factory recorded in the router, quoter, and position manager contracts all point to the same Factory contract, and the wrapped native token/USDC liquidity pool can be queried.
When used together with the built-in templates of exchange.IO("abi", ...), these contracts can be called directly without manually writing the ABI.
Currently only Ethereum (EVM) chains are supported; on TRON the call returns a null value with the error in GetLastError().