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

Batch-reads the results of multiple contract calls in a single request through the Multicall3 contract. It is suitable for batch querying balances, liquidity pool states, quotes, and other data, and can effectively reduce the number of RPC requests.

exchange.IO(k, calls)
exchange.IO(k, calls, options)

Examples

Read wallet balances and the Uniswap liquidity pool state simultaneously in a single request.

javascript
function main() { var USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" var WETH = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" var POOL = "0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640" // Uniswap V3 USDC/WETH 0.05% pool var owner = exchange.IO("address") exchange.IO("abi", POOL, JSON.stringify([ { type: "function", name: "slot0", stateMutability: "view", inputs: [], outputs: [ { name: "sqrtPriceX96", type: "uint160" }, { name: "tick", type: "int24" }, { name: "observationIndex", type: "uint16" }, { name: "observationCardinality", type: "uint16" }, { name: "observationCardinalityNext", type: "uint16" }, { name: "feeProtocol", type: "uint8" }, { name: "unlocked", type: "bool" }] }, { type: "function", name: "liquidity", stateMutability: "view", inputs: [], outputs: [{ type: "uint128" }] } ])) // Each item is written the same way as exchange.IO("call", ...): [contract address, method, // ...arguments], all read in a single request var ret = exchange.IO("multicall", [ [USDC, "balanceOf", owner], [WETH, "balanceOf", owner], [POOL, "slot0"], [POOL, "liquidity"] ]) Log("USDC balance:", ret[0], "WETH balance:", ret[1]) Log("Pool tick:", ret[2].tick, "Liquidity:", ret[3]) // By default, if any item fails, the entire result is null; when allowFailure is true, failed // items are null var ret2 = exchange.IO("multicall", [[USDC, "decimals"], [USDC, "transfer", POOL, 1]], { allowFailure: true }) Log("decimals:", ret2[0], "transfer (the caller is the Multicall3 contract, not the wallet):", ret2[1]) }

Returns

TypeDescription

array

Returns an array of results in the same order as calls. Each item is decoded the same way as with exchange.IO("call", ...). Note that the caller (msg.sender) of every sub-call is the Multicall3 contract, whereas exchange.IO("call", ...) calls from the wallet address by default, so methods that depend on the caller (such as transfer, or write methods that check the caller's balance or allowance) give different results; exchange.IO("multicall", ...) is meant for reads that do not depend on the caller.

Arguments

NameTypeRequiredDescription

k

string

Yes

Function of the exchange.IO() function. When set to multicall, it indicates that the function is used to batch-read contract call results.

calls

array

Yes

Array of calls. Each item in the array has the format [contract address, method, ...arguments], written in the same way as exchange.IO("call", ...), where the method can also be the complete call data (calldata). payable calls that attach native tokens are not supported.

options

object

No

Contains optional settings: when allowFailure is set to true, failed calls return a null value; otherwise (by default), if any call fails, the entire result is a null value, and the index and reason of the failed call can be obtained through GetLastError(). block is used to specify the block to read from (defaults to latest; a negative number indicates an offset relative to the latest block). multicall is used to specify the Multicall3 contract address (defaults to 0xcA11bde05977b3631167028862bE2a173976CA11; this contract is deployed at this address on all mainstream EVM chains).

See Also

Remarks

All calls are executed against the same block state, so the returned results are consistent with one another.

Currently only Ethereum (EVM) chains are supported; TRON is not supported yet.