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

Queries the event logs of a contract (eth_getLogs) and decodes them according to the ABI. It supports filtering by block range and by the indexed parameters of events, and can be used to monitor on-chain events such as trades, incoming transfers, and liquidity pool changes.

exchange.IO(k, query)

Examples

Query USDC transfer events and Swap events of a Uniswap liquidity pool.

javascript
function main() { var USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" var POOL = "0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640" // Uniswap V3 USDC/WETH 0.05% pool // The Transfer event of tokens is supported natively; a negative fromBlock indicates an offset // relative to the latest block var transfers = exchange.IO("logs", { address: USDC, event: "Transfer", fromBlock: -2 }) Log("USDC transfers in the last 3 blocks:", transfers.length, "entries") if (transfers.length > 0) { var t = transfers[0] Log(t.blockNumber, t.transactionHash, t.args.from, "→", t.args.to, t.args.value) // Filter by indexed parameters var mine = exchange.IO("logs", { address: USDC, event: "Transfer", fromBlock: -2, filter: { from: t.args.from } }) Log("Same sender:", mine.length, "entries") } // For events of other contracts, the ABI containing the event must be registered first exchange.IO("abi", POOL, JSON.stringify([{ type: "event", name: "Swap", anonymous: false, inputs: [ { indexed: true, name: "sender", type: "address" }, { indexed: true, name: "recipient", type: "address" }, { indexed: false, name: "amount0", type: "int256" }, { indexed: false, name: "amount1", type: "int256" }, { indexed: false, name: "sqrtPriceX96", type: "uint160" }, { indexed: false, name: "liquidity", type: "uint128" }, { indexed: false, name: "tick", type: "int24" }] }])) var swaps = exchange.IO("logs", { address: POOL, event: "Swap", fromBlock: -20 }) swaps.forEach(function (s) { Log("Swap block", s.blockNumber, "amount0:", s.args.amount0, "amount1:", s.args.amount1, "tick:", s.args.tick) }) }

Returns

TypeDescription

array

Returns an array of logs. Each entry contains address (lowercase), blockNumber, logIndex, transactionIndex (numbers), transactionHash, blockHash, topics, data and removed, plus event (the event name) and args (the arguments) when it can be decoded by an ABI.

Arguments

NameTypeRequiredDescription

k

string

Yes

Function of the exchange.IO() function. When set to logs, it indicates that the function is used to query event logs.

query

object

Yes

Query conditions: address is the contract address (a string or an array); event is the event name or the full event signature (for example, "Transfer(address,address,uint256)"); filter is an object for filtering by indexed parameter names, and when a value is an array, it matches any one of the values in it; fromBlock and toBlock are used to specify the block range (they can be numbers or tags such as latest; a negative number indicates an offset relative to the latest block, and both default to latest); topics or blockHash can also be set directly.

See Also

Remarks

The Transfer and Approval events of tokens are supported natively; for other events, the ABI containing the event must first be registered via exchange.IO("abi", ...).

When the node imposes limits on the block span of the query or the number of returned entries, the error message given by the node will be returned. In this case, you can narrow the block range and query in segments.

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