exchange.IO("abi", ...)
On the FMZ Quant Trading Platform, various blockchain-related functions and calls are mainly implemented through the exchange.IO() function. The following documentation describes the different calling methods of the exchange.IO() function separately by functionality. The exchange.IO("abi", ...) calling method is used to register an ABI.
-
Supports Ethereum (eth)
-
Supports TRON (tron)
exchange.IO(k, address, abiContent)Examples
-
Register the ABI fragment of the exactOutput method of Uniswap's SwapRouter02 contract.
javascriptfunction main() { // register Uniswap SwapRouter02 abi var routerAddress = "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45" var abi = `[{"inputs":[{"components":[{"internalType":"bytes","name":"path","type":"bytes"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"uint256","name":"amountInMaximum","type":"uint256"}],"internalType":"struct IV3SwapRouter.ExactOutputParams","name":"params","type":"tuple"}],"name":"exactOutput","outputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"}],"stateMutability":"payable","type":"function"}]` // The abi only contains the exactOutput method portion; the complete abi can be found by // searching online exchange.IO("abi", routerAddress, abi) } -
Register the Uniswap V3 position manager contract using a built-in template, and query the most recently added positions.
javascriptfunction main() { // Uniswap V3 position manager contract (Ethereum mainnet) var npm = "0xC36442b4a4522E871399CD717aBDD847Ab11FE88" // Pass the template name as the second parameter to use the built-in ABI of commonly used // contracts exchange.IO("abi", npm, "uniswapV3PositionManager") // The template contains event definitions: query positions with increased liquidity in the most // recent 100 blocks var logs = exchange.IO("logs", { address: npm, event: "IncreaseLiquidity", fromBlock: -100 }) if (logs.length > 0) { var id = logs[logs.length - 1].args.tokenId var pos = exchange.IO("api", npm, "positions", id) Log("Position", id, "Owner:", exchange.IO("api", npm, "ownerOf", id)) Log("Range tick:", pos.tickLower, "~", pos.tickUpper, "Liquidity:", pos.liquidity) } }
Arguments
| Name | Type | Required | Description |
k | string | Yes | Functionality of the |
address | string | Yes | Address of the smart contract. |
abiContent | string | Yes | The smart contract's |
See Also
Remarks
If the smart contract method being called is a standard ERC20 method, there is no need to register the ABI.
The ABI content of a contract can be obtained via Etherscan's V2 API (an Etherscan API key is required, chainid is the chain ID); only the result field is needed, for example:
url
https://api.etherscan.io/v2/api?chainid=1&module=contract&action=getabi&address=0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45&apikey=YourApiKey
When calling by method name, methods in the ABI registered for that address are matched first, followed by the built-in ERC20 methods; for overloaded methods with the same name, the full method signature must be used to distinguish them, for example "permit(address,((address,uint160,uint48,uint48),address,uint256),bytes)".
The built-in templates contain commonly used function and event definitions. The event definitions can be used together with exchange.IO("logs", ...) and exchange.IO("waitReceipt", ...) for decoding; the addresses of commonly used contracts can be obtained via exchange.IO("contracts", ...).
On TRON, calling a method of a contract whose ABI has not been registered reads the contract's ABI from the chain automatically and caches it; if the chain has none, an error is reported and the ABI must be registered manually with exchange.IO("abi", ...).
A built-in template name can be passed as abiContent instead: weth (the wrapped native coin's deposit and withdraw methods, aliases wbnb and wrappedNative), uniswapV3Pool, uniswapV3Factory, uniswapV3QuoterV2, uniswapV3SwapRouter02, uniswapV3PositionManager and permit2. The corresponding PancakeSwap V3 contracts use the same templates and can also be written as pancakeV3Pool, pancakeV3Factory, pancakeV3QuoterV2, pancakeV3SmartRouter and pancakeV3PositionManager, or with the generic aliases v3Pool, v3Factory, v3QuoterV2, v3Router and v3PositionManager. An unknown template name is an error.