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

Connects to an EVM or TRON chain node (the ChainType option: an EVM chain or TRON) and reads and writes on-chain data through the commands of exchange.IO(): calling contracts after registering their ABI, encoding and decoding, signing, batched reads, event logs, sending transactions and managing nonces. On EVM it uses the node's JSON-RPC, and the chain is whatever chain the node serves (Ethereum, BNB Smart Chain, Base, Arbitrum or any other EVM chain); on TRON it uses the full node's HTTP interface (/wallet/*).

Of the standard trading functions only exchange.GetAssets() and exchange.GetAccount() (the wallet's native coin balance) are supported. To swap tokens on a decentralized exchange, use the Uniswap exchange object instead: it supports the standard functions such as exchange.GetTicker() and exchange.CreateOrder().

Names and Configuration

exchange.GetName(): Web3 (Custom access); aliases: Ethereum, TRON.

FieldRequiredDefaultDescription
ChainYesETHPicking an EVM chain (Ethereum, BNB Chain, Base, Arbitrum, OP Mainnet, Polygon, Avalanche C-Chain or Unichain) fills in that chain's public nodes; for any other EVM chain pick "Other EVM" and enter the node address yourself; TRON is the TRON chain. (more below the table)
Private KeyYes—Wallet private key (hex, 0x prefix optional). It can be left empty for read-only use and switched at run time with exchange.IO("key", ...).
Rpc AddressNohttps://ethereum-rpc.publicnode.com,https://eth.drpc.orgThe JSON-RPC node address on EVM, with several nodes separated by commas backing each other up; left empty, the selected chain's public nodes are used ("Other EVM" requires one). (more below the table)
Rpc Api KeyNo—EVM: a Header-Name: value header or a Basic auth value; TRON: sent as the TRON-PRO-API-KEY header.

The rest of the longer descriptions in the table:

  • Chain: On EVM the chain actually used is still the node's chainId (the option only sets the default nodes), so existing configurations of ETH plus a custom node keep working on any EVM chain. Options: Ethereum, BNB Chain, Base, Arbitrum, OP Mainnet, Polygon, Avalanche C-Chain, Unichain, Other EVM (custom RPC), TRON
  • Rpc Address: Public nodes are rate-limited, so use your own node for frequent calls or historical log queries. On TRON, the full-node HTTP address (only one; empty means https://api.trongrid.io, and legacy gRPC addresses are mapped to their HTTP counterparts).

Trading Pairs and Contract Codes

Pair examples: ETH_USDT

The trading pair plays no part in on-chain operations; any BASE_QUOTE form can be set. Contracts and tokens are given by address: 0x-prefixed on EVM, T-prefixed on TRON.

Exchange-specific IO Commands
CommandArgumentsDescriptionReturns
abiaddress, abiContentRegister the ABI of a contract address (a JSON string, or one of the built-in templates weth, uniswapV3Pool, uniswapV3Factory, uniswapV3QuoterV2, uniswapV3SwapRouter02, uniswapV3PositionManager, permit2, with matching pancakeV3* aliases for PancakeSwap V3). See the sub-page exchange.IO("abi", ...).—
apiaddress | "eth" | "tron", method, ...args[, options]With a contract address as the first argument, calls a contract method; read-only methods (view, pure) return the decoded value, and write methods are signed and broadcast and return the transaction hash (options may set gasLimit, gasPrice, nonce, dryRun). See the sub-page exchange.IO("api", ...).—
calladdress, method | calldata, ...args[, options]Simulate any contract method (including write methods) with eth_call, without signing, broadcasting or spending gas, for quotes and dry runs; options is {from, value, block, gasLimit}. EVM only. See the sub-page exchange.IO("call", ...).The decoded value when called by method name (true for a method without return values); the raw return data (a hex string) when called with calldata.
multicallcalls[, options]Read several contract calls in one request on the same block state through the Multicall3 contract; each item of calls is [address, method, ...args], and options is {allowFailure, block, multicall}. See the sub-page exchange.IO("multicall", ...).An array of results in the order of calls. By default any failing item fails the whole call (with its index and reason); with allowFailure true, failed items are null.
logsqueryQuery a contract's event logs (eth_getLogs) and decode them by ABI; query is {address, event, filter, fromBlock, toBlock, topics, blockHash}. EVM only. See the sub-page exchange.IO("logs", ...).An array of logs, each with event and args when it can be decoded.
waitReceipttxHash[, options]Wait until a transaction is mined and has the required confirmations; options is {timeout, confirmations, interval}: timeout and interval are in milliseconds, 120000 (1000 to 600000) and 1500 by default, and confirmations defaults to 1. See the sub-page exchange.IO("waitReceipt", ...).The transaction receipt (status as a number, events decoded); an error and null on timeout.
nonce["sync" | number]Show the nonce counter used for sending transactions; sync resyncs it from the node's pending count, and a number sets the next local nonce. EVM only. See the sub-page exchange.IO("nonce", ...).{address, latest, pending, local} (all values are strings; local is null before any transaction has been sent).
speedUptxHash[, options]Resend a pending transaction with a higher fee (same nonce, recipient, amount, call data and gas limit); options is {multiplier, dryRun}, multiplier 1.1 to 10, default 1.125. EVM only. See the sub-page exchange.IO("speedUp", ...).The replacement transaction's hash; its content with dryRun.
cancelTxtxHash[, options]Cancel a pending transaction by sending a zero-amount transaction to yourself with the same nonce and a higher fee; options as for speedUp. Success is not guaranteed. EVM only. See the sub-page exchange.IO("cancelTx", ...).The cancel transaction's hash; its content with dryRun.
encode[address, ]dataFormat, ...argsStandard ABI encoding by a type list (like Solidity's abi.encode); with a contract address as the first argument, encodes a method call of that contract (calldata). See the sub-page exchange.IO("encode", ...).A hex string without 0x.
encodePackeddataFormat, ...argsPacked encoding by a type list (like Solidity's abi.encodePacked). See the sub-page exchange.IO("encodePacked", ...).A hex string without 0x.
decodedataFormat, dataDecode hex data by a type list. See the sub-page exchange.IO("decode", ...).The value itself for a single type, an array for several.
hashalgo, inputFormat, outputFormat, data[, keyFormat, key]Compute hash digests and HMACs, sign with the configured private key and so on, with the same parameters as the Encode function; commonly used for keccak256. See the sub-page exchange.IO("hash", ...).—
keyprivateKeySwitch the private key used by the exchange object (hex, 0x prefix optional); an invalid key fails and nothing is switched. Do not switch concurrently. See the sub-page exchange.IO("key", ...).—
signhash[, key]Sign a 32-byte hash with a secp256k1 private key (no further hashing), for off-chain signatures such as EIP-712; the configured key is used when key is omitted. See the sub-page exchange.IO("sign", ...).{r, s, v, signature, vs} (v is 27 or 28, vs the EIP-2098 compact signature).
signTypedDatatypedData[, key] | domain, types, message[, key]Sign structured data per EIP-712, computing the type hash, domain separator, struct hash and digest in one call. See the sub-page exchange.IO("signTypedData", ...).As for sign, plus digest (the EIP-712 digest).
signMessagemessage[, key]Sign a message per EIP-191 (personal_sign); a string is signed as UTF-8, raw bytes are passed as {hex: "0x..."}. See the sub-page exchange.IO("signMessage", ...).As for sign, plus digest (the EIP-191 message hash).
toUnitsamount, decimalsConvert a readable amount into an on-chain integer with exact string arithmetic; decimals may be a number or a token contract address (its decimals() is read). More fractional digits than the precision fail. See the sub-page exchange.IO("toUnits", ...).A decimal string.
fromUnitsamount, decimalsConvert an on-chain integer into a readable amount with exact string arithmetic; decimals as for toUnits. See the sub-page exchange.IO("fromUnits", ...).A decimal string (trailing zeros removed).
uniswapV3fn, ...argsConcentrated-liquidity math: tickToPrice, priceToTick, sqrtPriceToPrice, tickToSqrtPrice, sqrtPriceToTick, nearestUsableTick, amountsForLiquidity, liquidityForAmounts; precision arguments may be numbers or token addresses. See the sub-page exchange.IO("uniswapV3", ...).—
contracts[chainId]Common contract addresses of the current (or given) chain: major tokens, Multicall3, Permit2, and the Factory, router, QuoterV2 and position manager of Uniswap V3 and PancakeSwap V3. See the sub-page exchange.IO("contracts", ...).{chainId, name, wrappedNative, tokens, multicall3, permit2, uniswapV3, pancakeV3}
address[key]The configured wallet address (lowercase 0x on EVM, T-prefixed on TRON); with a private key, returns that key's address without switching keys. See the sub-page exchange.IO("address").—
base[address]Query or set the RPC node address. On EVM several nodes back each other up (an array or a comma-separated string), and each node's chainId is checked on first use; on TRON only one full-node HTTP address is supported, and legacy gRPC addresses such as grpc.trongrid.io:50051 are mapped to their HTTP counterparts. See the sub-page exchange.IO("base", ...).The previous node address; the current one when called without an argument.
sendBase[url]Set a node used only to broadcast transactions (private channels such as Flashbots Protect or MEV Blocker); reads, nonce queries and gas estimates still use the configured node; an empty string clears it. EVM only. See the sub-page exchange.IO("sendBase", ...).The previous broadcast node, or an empty string if none was set.

For the common command currency see exchange.IO.

Function Support

Not supported (the call fails with an error and returns null): exchange.GetTicker, exchange.GetTickers, exchange.GetDepth, exchange.GetTrades, exchange.GetRecords, exchange.GetMarkets, exchange.CreateOrder, exchange.Buy, exchange.Sell, exchange.CancelOrder, exchange.ModifyOrder, exchange.GetOrder, exchange.GetOrders, exchange.GetHistoryOrders, exchange.CreateConditionOrder, exchange.ModifyConditionOrder, exchange.CancelConditionOrder, exchange.GetConditionOrder, exchange.GetConditionOrders, exchange.GetHistoryConditionOrders.

Notes
  • exchange.GetAssets() returns the wallet's native coin balance: on EVM the coin is named from the node's chainId (ETH, BNB, POL, AVAX and so on; an unknown chain fails), on TRON it is TRX; exchange.GetAccount() picks from it by the current pair (with ETH_USDT, Stocks is the ETH balance). Query token balances with exchange.IO("api", tokenAddress, "balanceOf", address).

In this sectionRead the whole section

NameDescription
exchange.IO("abi", ...)On the FMZ Quant Trading Platform, various blockchain-related functions and calls are mainly implemented through the exchange.IO() function.
exchange.IO("api", blockChain, ...)Calls Ethereum RPC methods (select eth when configuring the Web3 exchange object).
exchange.IO("encode", ...)Encodes data using ABI encoding.
exchange.IO("encodePacked", ...)Performs encodePacked encoding operations.
exchange.IO("decode", ...)Decodes data.
exchange.IO("hash", ...)Computes hash digests and HMACs, signs with the private key configured on the exchange object, and so on.
exchange.IO("key", ...)Switches the private key.
exchange.IO("sign", ...)Signs a 32-byte hash with a secp256k1 private key and returns signature data such as r, s, and v.
exchange.IO("signTypedData", ...)Signs structured data according to the EIP-712 standard.
exchange.IO("signMessage", ...)Signs messages according to the EIP-191 standard (personal_sign).
exchange.IO("api", ...)Calls a smart contract method on a Web3 exchange object.
exchange.IO("call", ...)Simulates the execution of any smart contract method (including write methods that modify on-chain state) via eth_call.
exchange.IO("multicall", ...)Batch-reads the results of multiple contract calls in a single request through the Multicall3 contract.
exchange.IO("logs", ...)Queries the event logs of a contract (eth_getLogs) and decodes them according to the ABI.
exchange.IO("waitReceipt", ...)Waits for a transaction to be included on-chain and reach the specified number of confirmations, returning the transaction receipt and the decoded event logs.
exchange.IO("nonce", ...)Queries, synchronizes or sets the nonce counter used when sending transactions.
exchange.IO("speedUp", ...)Resends a stuck transaction (one that has not been mined for a long time) with a higher fee: the recipient address, amount, call data, and gas limit remain unch…
exchange.IO("cancelTx", ...)Cancels a transaction that has not yet been included on-chain: it sends a zero-amount transaction to yourself using the same nonce as the original transaction w…
exchange.IO("toUnits", ...)Converts a human-readable amount into an on-chain integer.
exchange.IO("fromUnits", ...)Converts an on-chain integer value into a human-readable amount.
exchange.IO("uniswapV3", ...)Performs concentrated liquidity (Uniswap V3) calculations, including conversions between tick, price, and sqrtPriceX96, as well as conversions between liquidity…
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,…
exchange.IO("address")Returns the address of the wallet configured on the exchange object.
exchange.IO("base", ...)Set the RPC node address of a Web3 exchange object; on EVM chains several nodes can back each other up.
exchange.IO("sendBase", ...)Sets a node dedicated solely to broadcasting transactions.