exchange.IO("api", ...)
The exchange.IO("api", ...) function is used to call smart contract methods.
exchange.IO(k, address, method)
exchange.IO(k, address, method, ...args)
exchange.IO(k, address, method, value, ...args)Examples
-
The
decimalsmethod is aconstantmethod of ERC20 that does not consume gas and can query the precision data of a token.The
decimalsmethod requires no parameters. Return value: the precision data of the token.javascriptfunction main(){ var tokenAddress = "0x111111111117dC0aa78b770fA6A738034120C302" // 代币的合约地址,例子中的代币为1INCH Log(exchange.IO("api", tokenAddress, "decimals")) // 查询,打印1INCH代币的精度指数为18 } -
The
allowancemethod is aconstantmethod of ERC20 that does not consume gas and can query the authorized amount of a token for a specific contract address.The
allowancemethod requires 2 parameters: the first parameter is the wallet address, and the second parameter is the authorized address. Return value: the authorized amount of the token.owner: wallet address, represented by the string "owner" in the example, actual use requires filling in the specific address.spender: the authorized contract address, represented by the string "spender" in the example, actual use requires filling in the specific address, for example, it can be theUniswap V3 router v1address.javascriptfunction main(){ // 代币的合约地址,例子中的代币为1INCH var tokenAddress = "0x111111111117dC0aa78b770fA6A738034120C302" // 例如查询得出1000000000000000000,除以该token的精度单位1e18,得出当前交易所对象绑定的钱包给spender地址授权了1个1INCH数量 Log(exchange.IO("api", tokenAddress, "allowance", "owner", "spender")) } -
The
approvemethod is a non-constantmethod of ERC20 that consumes gas and is used to authorize a contract address with an operational amount of tokens.The
approvemethod requires 2 parameters: the first parameter is the authorized address, and the second parameter is the authorized amount. Return value: txid.spender: the authorized contract address, represented by the string "spender" in the example, actual use requires filling in the specific address, for example, it can be theUniswap V3 router v1address.0xde0b6b3a7640000: the authorized amount, represented here as a hexadecimal string, corresponding to the decimal value of 1e18, divided by the token precision unit in the example (i.e., 1e18), resulting in authorization of 1 token.The third parameter of the
exchange.IO()function passes the method nameapprove, which can also be written in methodId form, for example: "0x571ac8b0". It can also be written as the complete standard method name, for example: "approve(address,uint256)".javascriptfunction main(){ // 代币的合约地址,例子中的代币为1INCH var tokenAddress = "0x111111111117dC0aa78b770fA6A738034120C302" // 授权量的十六进制字符串: 0xde0b6b3a7640000 , 对应的十进制字符串: 1e18 , 1e18除以该token的精度单位,即1个代币数量 , 所以这里指授权一个代币 Log(exchange.IO("api", tokenAddress, "approve", "spender", "0xde0b6b3a7640000")) } -
The
multicallmethod is a non-constantmethod ofUniswap V3that consumes gas and is used for multi-path token swaps.The
multicallmethod may have multiple parameter passing methods. You can query the ABI containing this method for details. The ABI needs to be registered before calling this method. Return value: txid.For specific
multicallmethod call examples, you can refer to the platform's public "Uniswap V3 Trading Library" templateHere we use pseudocode to describe some details:
javascriptexchange.IO("api", ContractV3SwapRouterV2, "multicall(uint256,bytes[])", value, deadline, data)ContractV3SwapRouterV2: The router v2 address of Uniswap V3.value: The amount of ETH to transfer. If the tokenIn token for the swap operation is not ETH, set it to 0.deadline:deadlineis a parameter of themulticallmethod, which can be set to (new Date().getTime() / 1000) + 3600, indicating validity within one hour.data:datais a parameter of themulticallmethod, the packed operation data to be executed. Similar toexchange.IO("api", "eth", "send", "toAddress", toAmount), when calling themulticallmethod, you can also specify thegasLimit/gasPrice/noncesettings for the method call, also described using pseudocode:javascriptexchange.IO("api", ContractV3SwapRouterV2, "multicall(uint256,bytes[])", value, deadline, data, {gasPrice: 123456, gasLimit: 21000})You can set the
{gasPrice: 11, gasLimit: 111, nonce: 111}parameters according to specific requirements. This parameter is set as the last parameter of theexchange.IO()function.You can omit
nonceto use the system default value, or not setgasLimit/gasPrice/nonceto use all system default values.javascriptfunction main() { var ContractV3SwapRouterV2 = "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45" var tokenInName = "ETH" var amountIn = 0.01 var options = {gasPrice: 5000000000, gasLimit: 21000, nonce: 100} // 此处为举例,具体要根据实际场景设置 var data = "" // 编码后的数据,此处为空字符串,具体要根据实际场景设置 var tx = exchange.IO("api", ContractV3SwapRouterV2, "multicall(uint256,bytes[])", (tokenInName == 'ETH' ? amountIn : 0), (new Date().getTime() / 1000) + 3600, data, options || {}) }
Returns
| Type | Description |
string / number / bool / object / array / any (any type supported by the platform) | The |
Arguments
| Name | Type | Required | Description |
k | string | Yes | The |
address | string | Yes | The |
method | string | Yes | The |
value | number / string | No | The |
arg | string / number / bool / any (any type supported by the platform) | No | The There may be multiple |