Type/to search
Built-in Functions
Global
Version
Sleep
IsVirtual
Mail
Mail_Go
SetErrorFilter
GetPid
GetLastError
GetCommand
GetMeta
Dial
HttpQuery
HttpQuery_Go
Encode
UnixNano
Unix
GetOS
MD5
DBExec
UUID
EventLoop
__Serve
_G
_D
_N
_C
_Cross
JSON.parse
JSON.stringify
SetChannelData
GetChannelData
Log
Market
Trade
Account
Futures
NetSettings
Threads
threading
Thread
getThread
mainThread
currentThread
Lock
Condition
Event
Dict
pending
Thread
ThreadLock
ThreadEvent
ThreadCondition
ThreadDict
Web3
TA
Talib
talib.CDL2CROWS
talib.CDL3BLACKCROWS
talib.CDL3INSIDE
talib.CDL3LINESTRIKE
talib.CDL3OUTSIDE
talib.CDL3STARSINSOUTH
talib.CDL3WHITESOLDIERS
talib.CDLABANDONEDBABY
talib.CDLADVANCEBLOCK
talib.CDLBELTHOLD
talib.CDLBREAKAWAY
talib.CDLCLOSINGMARUBOZU
talib.CDLCONCEALBABYSWALL
talib.CDLCOUNTERATTACK
talib.CDLDARKCLOUDCOVER
talib.CDLDOJI
talib.CDLDOJISTAR
talib.CDLDRAGONFLYDOJI
talib.CDLENGULFING
talib.CDLEVENINGDOJISTAR
talib.CDLEVENINGSTAR
talib.CDLGAPSIDESIDEWHITE
talib.CDLGRAVESTONEDOJI
talib.CDLHAMMER
talib.CDLHANGINGMAN
talib.CDLHARAMI
talib.CDLHARAMICROSS
talib.CDLHIGHWAVE
talib.CDLHIKKAKE
talib.CDLHIKKAKEMOD
talib.CDLHOMINGPIGEON
talib.CDLIDENTICAL3CROWS
talib.CDLINNECK
talib.CDLINVERTEDHAMMER
talib.CDLKICKING
talib.CDLKICKINGBYLENGTH
talib.CDLLADDERBOTTOM
talib.CDLLONGLEGGEDDOJI
talib.CDLLONGLINE
talib.CDLMARUBOZU
talib.CDLMATCHINGLOW
talib.CDLMATHOLD
talib.CDLMORNINGDOJISTAR
talib.CDLMORNINGSTAR
talib.CDLONNECK
talib.CDLPIERCING
talib.CDLRICKSHAWMAN
talib.CDLRISEFALL3METHODS
talib.CDLSEPARATINGLINES
talib.CDLSHOOTINGSTAR
talib.CDLSHORTLINE
talib.CDLSPINNINGTOP
talib.CDLSTALLEDPATTERN
talib.CDLSTICKSANDWICH
talib.CDLTAKURI
talib.CDLTASUKIGAP
talib.CDLTHRUSTING
talib.CDLTRISTAR
talib.CDLUNIQUE3RIVER
talib.CDLUPSIDEGAP2CROWS
talib.CDLXSIDEGAP3METHODS
talib.AD
talib.ADOSC
talib.OBV
talib.ACOS
talib.ASIN
talib.ATAN
talib.CEIL
talib.COS
talib.COSH
talib.EXP
talib.FLOOR
talib.LN
talib.LOG10
talib.SIN
talib.SINH
talib.SQRT
talib.TAN
talib.TANH
talib.MAX
talib.MAXINDEX
talib.MIN
talib.MININDEX
talib.MINMAX
talib.MINMAXINDEX
talib.SUM
talib.HT_DCPERIOD
talib.HT_DCPHASE
talib.HT_PHASOR
talib.HT_SINE
talib.HT_TRENDMODE
talib.ATR
talib.NATR
talib.TRANGE
talib.BBANDS
talib.DEMA
talib.EMA
talib.HT_TRENDLINE
talib.KAMA
talib.MA
talib.MAMA
talib.MIDPOINT
talib.MIDPRICE
talib.SAR
talib.SAREXT
talib.SMA
talib.T3
talib.TEMA
talib.TRIMA
talib.WMA
talib.LINEARREG
talib.LINEARREG_ANGLE
talib.LINEARREG_INTERCEPT
talib.LINEARREG_SLOPE
talib.STDDEV
talib.TSF
talib.VAR
talib.ADX
talib.ADXR
talib.APO
talib.AROON
talib.AROONOSC
talib.BOP
talib.CCI
talib.CMO
talib.DX
talib.MACD
talib.MACDEXT
talib.MACDFIX
talib.MFI
talib.MINUS_DI
talib.MINUS_DM
talib.MOM
talib.PLUS_DI
talib.PLUS_DM
talib.PPO
talib.ROC
talib.ROCP
talib.ROCR
talib.ROCR100
talib.RSI
talib.STOCH
talib.STOCHF
talib.STOCHRSI
talib.TRIX
talib.ULTOSC
talib.WILLR
talib.AVGPRICE
talib.MEDPRICE
talib.TYPPRICE
talib.WCLPRICE
OS
Structures
Built-in Variables

In the FMZ Quant Trading Platform, various blockchain-related functions are mainly implemented through the exchange.IO() function. The following documentation will describe the different functions of the exchange.IO() function separately. The exchange.IO("abi", ...) function call is used to register ABI.

  • Supports Ethereum (eth)

  • Supports TRON (tron)

exchange.IO(k, address, abiContent)

Examples

javascript
function 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"}]` // abi only uses partial exactOutput method content, complete abi can be searched online exchange.IO("abi", routerAddress, abi) }

Arguments

NameTypeRequiredDescription

k

string

Yes

The k parameter is used to set the function of exchange.IO(). Setting it to "abi" indicates that this function is used to register ABI.

address

string

Yes

The address parameter is used to specify the smart contract address.

abiContent

string

Yes

The abiContent parameter is used to specify the smart contract's ABI.

Remarks

If the called smart contract method is a standard ERC20 method, registration is not required.

To obtain the contract's ABI content, you can use the following URL, just take the result field, for example:

url
https://api.etherscan.io/api?module=contract&action=getabi&address=0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45

The exchange.IO("api", "eth", ...) function call is used to invoke Ethereum RPC methods (requires selecting eth when configuring the Web3 exchange object).

exchange.IO("api", "tron", ...) function call is used to invoke TRON RPC methods (requires selecting tron when configuring the Web3 exchange object).

exchange.IO(k, blockChain, rpcMethod)
exchange.IO(k, blockChain, rpcMethod, ...args)

Examples

  • Query ETH balance in wallet:

    javascript
    function main() { // "owner" needs to be replaced with the actual wallet address // Parameter label at "latest" string position: 'latest', 'earliest' or 'pending', refer to https://eth.wiki/json-rpc/API#the-default-block-parameter // Return value ethBalance is a hexadecimal string: 0x9b19ce56113070 var ethBalance = exchange.IO("api", "eth", "eth_getBalance", "owner", "latest") // ETH precision unit is 1e18 var ethDecimal = 18 // Due to JavaScript language precision limitations, need to use system-level encapsulated functions BigInt, BigDecimal for processing // Convert ethBalance to readable amount, 0x9b19ce56113070 converts to 0.043656995388076145 Log(Number((BigDecimal(BigInt(ethBalance))/BigDecimal(Math.pow(10, ethDecimal))).toString())) }
  • ETH transfer, you can set {gasPrice: 11, gasLimit: 111, nonce: 111} parameters according to specific requirements, this parameter is set as the last parameter of the exchange.IO() function. You can omit nonce to use system default value, or not set gasLimit/gasPrice/nonce to use all system default values.

    javascript
    function mian() { // ETH precision unit is 1e18 var ethDecimal = 18 // Transfer amount, readable amount for example: 0.01 ETH var sendAmount = 0.01 // Due to JavaScript language precision limitations, need to use system-level encapsulated functions BigInt, BigDecimal for processing, and convert readable amount to on-chain processing data var toAmount = (BigDecimal(sendAmount)*BigDecimal(Math.pow(10, ethDecimal))).toFixed(0) // "toAddress" is the recipient's ETH wallet address for the transfer, needs to be specifically filled in, toAmount is the transfer amount exchange.IO("api", "eth", "send", "toAddress", toAmount) }
  • Query gasPrice:

    javascript
    function toAmount(s, decimals) { return Number((BigDecimal(BigInt(s))/BigDecimal(Math.pow(10, decimals))).toString()) } function main() { var gasPrice = exchange.IO("api", "eth", "eth_gasPrice") Log("gasPrice:", toAmount(gasPrice, 0)) // 5000000000 , in wei (5 gwei) }
  • Query eth_estimateGas:

    javascript
    function toAmount(s, decimals) { // toAmount函数可以将十六进制编码的数值转换为十进制数值 return Number((BigDecimal(BigInt(s))/BigDecimal(Math.pow(10, decimals))).toString()) } function main() { // 编码approve(授权)方法的调用 var data = exchange.IO("encode", "0x111111111117dC0aa78b770fA6A738034120C302", "approve", "0xe592427a0aece92de3edee1f18e0157c05861564", "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") Log("data:", data) var gasPrice = exchange.IO("api", "eth", "eth_gasPrice") Log("gasPrice:", toAmount(gasPrice, 0)) var obj = { "from" : "0x0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", // walletAddress "to" : "0x111111111117dC0aa78b770fA6A738034120C302", "gasPrice" : gasPrice, "value" : "0x0", "data" : "0x" + data, } var gasLimit = exchange.IO("api", "eth", "eth_estimateGas", obj) Log("gasLimit:", toAmount(gasLimit, 0)) Log("gas fee", toAmount(gasLimit, 0) * toAmount(gasPrice, 0) / 1e18) }

Returns

TypeDescription

string / number / bool / object / array / any (any type supported by the platform)

The exchange.IO("api", "eth", ...) function returns the return value of the called RPC method.

Arguments

NameTypeRequiredDescription

k

string

Yes

The k parameter is used to set the function of exchange.IO(). Setting it to "api" indicates that this function is used for extended call requests.

blockChain

string

Yes

The blockChain parameter is used to set the function of exchange.IO(). Setting it to "eth" indicates that this function is used to call Ethereum network RPC methods; setting it to "tron" indicates that this function is used to call TRON network RPC methods.

rpcMethod

string

Yes

The rpcMethod parameter is used to set the RPC method to be called by the exchange.IO() function.

arg

string / number / bool / object / array / function / any (any type supported by the platform)

No

The arg parameter is used to specify the parameters of the RPC method to be called.

There may be multiple arg parameters. The type and number of arg parameters depend on the RPC method specified by the rpcMethod parameter.

See Also

Remarks

When the second parameter of the exchange.IO() function is "eth", you can directly call RPC methods available on Ethereum node servers.

The exchange.IO("encode", ...) function is used for data encoding operations.

exchange.IO(k, dataFormat, ...args)
exchange.IO(k, address, dataFormat)
exchange.IO(k, address, dataFormat, ...args)

Examples

  • Taking the encoding of unwrapWETH9 method call as an example:

    javascript
    function main() { // ContractV3SwapRouterV2 主网地址 : 0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45 // 调用unwrapWETH9方法需要先注册ABI,此处省略注册 // "owner"代表钱包地址,需要具体填写,1代表解包装数量,把一个WETH解包装为ETH var data = exchange.IO("encode", "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45", "unwrapWETH9(uint256,address)", 1, "owner") Log(data) }
  • Encoding example equivalent to abi.encode in Solidity:

    javascript
    function main() { var x = 10 var address = "0x02a5fBb259d20A3Ad2Fdf9CCADeF86F6C1c1Ccc9" var str = "Hello World" var array = [1, 2, 3] var ret = exchange.IO("encode", "uint256,address,string,uint256[]", x, address, str, array) // uint 即 uint256 , FMZ上需要指定类型长度 Log("ret:", ret) /* 000000000000000000000000000000000000000000000000000000000000000a // x 00000000000000000000000002a5fbb259d20a3ad2fdf9ccadef86f6c1c1ccc9 // address 0000000000000000000000000000000000000000000000000000000000000080 // str 的偏移 00000000000000000000000000000000000000000000000000000000000000c0 // array 的偏移 000000000000000000000000000000000000000000000000000000000000000b // str 的长度 48656c6c6f20576f726c64000000000000000000000000000000000000000000 // str 数据 0000000000000000000000000000000000000000000000000000000000000003 // array 的长度 0000000000000000000000000000000000000000000000000000000000000001 // array 第一个数据 0000000000000000000000000000000000000000000000000000000000000002 // array 第二个数据 0000000000000000000000000000000000000000000000000000000000000003 // array 第三个数据 */ }
  • Supports encoding of tuples or type sequences containing tuples. This type sequence consists of tuple and bytes, so when calling exchange.IO() for encoding, two corresponding parameters need to be passed:

      1. Variable corresponding to tuple type:
      javascript
      { a: 30, b: 20, c: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2" }
      The passed parameters must be consistent with the structure and types of the tuple, as defined in the types parameter: tuple(a uint256,b uint8,c address).
      1. Variable corresponding to bytes type:
      javascript
      "0011"
    javascript
    function main() { var types = "tuple(a uint256,b uint8,c address),bytes" var ret = exchange.IO("encode", types, { a: 30, b: 20, c: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2" }, "0011") Log("encode: ", ret) }
  • Supports encoding of arrays or type sequences containing arrays:

    javascript
    function main() { var path = ["0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0xdac17f958d2ee523a2206206994597c13d831ec7"] // ETH address, USDT address var ret = exchange.IO("encode", "address[]", path) Log("encode: ", ret) }

Returns

TypeDescription

string

The exchange.IO("encode", ...) function returns the encoded data string.

Arguments

NameTypeRequiredDescription

k

string

Yes

The k parameter is used to set the functional mode of the exchange.IO() function. When set to "encode", it indicates that the function performs data encoding operations.

address

string

No

The address parameter is used to specify the smart contract address. When calling the exchange.IO("encode", ...) function, if the address parameter is passed, it indicates encoding a smart contract method call; if the address parameter is not passed, the function is used to encode in the specified type order, with functionality equivalent to abi.encode in Solidity.

dataFormat

string

Yes

The dataFormat parameter is used to specify the method name, data types, and parameter order for encoding data.

arg

string / number / tuple / array / any (any type supported by the platform)

No

The arg parameter is used to specify the specific data values that match the dataFormat parameter.

There may be multiple arg parameters, and their types and quantity depend on the settings of the dataFormat parameter.

Remarks

The exchange.IO() function encapsulates the encode method, which can encode function calls and return them as hex string format. For specific usage, please refer to the platform's public "Uniswap V3 Trading Library" template.

When encoding smart contract method calls, the corresponding ABI must be registered first.

The exchange.IO("encodePacked", ...) function is used to perform encodePacked encoding operations.

exchange.IO(k, dataFormat, ...args)

Examples

When using Uniswap V3, parameters such as trading path need to be passed in, which requires the use of encodePacked encoding operations:

javascript
function main() { var fee = exchange.IO("encodePacked", "uint24", 3000) var tokenInAddress = "0x111111111117dC0aa78b770fA6A738034120C302" var tokenOutAddress = "0x6b175474e89094c44da98b954eedeac495271d0f" var path = tokenInAddress.slice(2).toLowerCase() path += fee + tokenOutAddress.slice(2).toLowerCase() Log("path:", path) }

Returns

TypeDescription

string

The exchange.IO("encodePacked", ...) function returns a data string that has been processed with encodePacked encoding.

Arguments

NameTypeRequiredDescription

k

string

Yes

The k parameter is used to set the functional mode of the exchange.IO() function. When set to "encodePacked", it indicates that the function performs data encodePacked encoding operations.

dataFormat

string

Yes

The dataFormat parameter is used to specify the data type format and arrangement order for encodePacked encoding.

arg

string / number / tuple / array / any (any type supported by the platform)

Yes

The arg parameter is used to specify the specific data values that match the format of the dataFormat parameter.

There can be multiple arg parameters, and their type and quantity are determined by the settings of the dataFormat parameter.

The exchange.IO("decode", ...) function is used for data decoding operations.

exchange.IO(k, dataFormat, data)

Examples

  • Example of reverse operation for exchange.IO("encode", ...) function:

    javascript
    function main() { var types = "tuple(a uint256,b uint8,c address),bytes" var ret = exchange.IO("encode", types, { a: 30, b: 20, c: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2" }, "0011") Log("encode: ", ret) var rawData = exchange.IO("decode", types, ret) Log("decode:", rawData) }
  • The following example first performs an encodePacked operation on the path parameter, as the subsequent exactOutput method call that needs to be encoded requires path as a parameter. Then it encodes the exactOutput method of the router contract, which has only one parameter of tuple type. The encoded result of the exactOutput method name is: 0x09b81346. Using the exchange.IO("decode", ...) method to decode yields decodeRaw, whose result is consistent with the variable dataTuple.

    javascript
    function main() { // register SwapRouter02 abi var walletAddress = "0x398a93ca23CBdd2642a07445bCD2b8435e0a373f" 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"}]` exchange.IO("abi", routerAddress, abi) // abi只使用了局部的exactOutput方法的内容,完整的abi可以在网上搜索 // encode path var fee = exchange.IO("encodePacked", "uint24", 3000) var tokenInAddress = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2" var tokenOutAddress = "0xdac17f958d2ee523a2206206994597c13d831ec7" var path = tokenInAddress.slice(2).toLowerCase() path += fee + tokenOutAddress.slice(2).toLowerCase() Log("path:", path) var dataTuple = { "path" : path, "recipient" : walletAddress, "amountOut" : 1000, "amountInMaximum" : 1, } // encode SwapRouter02 exactOutput var rawData = exchange.IO("encode", routerAddress, "exactOutput", dataTuple) Log("method hash:", rawData.slice(0, 8)) // 09b81346 Log("params hash:", rawData.slice(8)) // decode exactOutput params var decodeRaw = exchange.IO("decode", "tuple(path bytes,recipient address,amountOut uint256,amountInMaximum uint256)", rawData.slice(8)) Log("decodeRaw:", decodeRaw) }

Returns

TypeDescription

array / string

The exchange.IO("decode", ...) function returns the decoded data. When the data structure specified by the dataFormat parameter contains only a single field, it returns a string type; when it contains multiple fields, it returns an array type.

Arguments

NameTypeRequiredDescription

k

string

Yes

The k parameter is used to set the functional mode of the exchange.IO() function. When set to "decode", it indicates performing a data decoding operation.

dataFormat

string

Yes

The dataFormat parameter is used to specify the format type and field order of the data to be decoded.

data

string

Yes

The data parameter is used to pass in the raw data that needs to be decoded.

Remarks

The exchange.IO() function supports bidirectional data processing, capable of both encoding (encode) and decoding (decode) operations.

The exchange.IO("key", ...) function is used to switch the private key calling method.

exchange.IO(k, key)

Examples

javascript
function main() { exchange.IO("key", "Private Key") // "Private Key" represents the private key string, which needs to be filled in specifically }

Arguments

NameTypeRequiredDescription

k

string

Yes

The k parameter is used to set the function of exchange.IO(). When set to "key", it indicates that the function is used to switch private keys.

key

string

Yes

The key parameter is used to set the private key string.

Remarks

The exchange.IO() function supports private key switching functionality, allowing operations on multiple wallet addresses. You can also add multiple exchange objects (refer to: exchanges) to operate multiple wallet addresses.

For private key switching operations: exchange.IO("key", "xxx"), concurrent switching is not supported.

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 decimals method is a constant method of ERC20 that does not consume gas and can query the precision data of a token.

    The decimals method requires no parameters. Return value: the precision data of the token.

    javascript
    function main(){ var tokenAddress = "0x111111111117dC0aa78b770fA6A738034120C302" // 代币的合约地址,例子中的代币为1INCH Log(exchange.IO("api", tokenAddress, "decimals")) // 查询,打印1INCH代币的精度指数为18 }
  • The allowance method is a constant method of ERC20 that does not consume gas and can query the authorized amount of a token for a specific contract address.

    The allowance method 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 the Uniswap V3 router v1 address.

    javascript
    function main(){ // 代币的合约地址,例子中的代币为1INCH var tokenAddress = "0x111111111117dC0aa78b770fA6A738034120C302" // 例如查询得出1000000000000000000,除以该token的精度单位1e18,得出当前交易所对象绑定的钱包给spender地址授权了1个1INCH数量 Log(exchange.IO("api", tokenAddress, "allowance", "owner", "spender")) }
  • The approve method is a non-constant method of ERC20 that consumes gas and is used to authorize a contract address with an operational amount of tokens.

    The approve method 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 the Uniswap V3 router v1 address.

    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 name approve, 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)".

    javascript
    function main(){ // 代币的合约地址,例子中的代币为1INCH var tokenAddress = "0x111111111117dC0aa78b770fA6A738034120C302" // 授权量的十六进制字符串: 0xde0b6b3a7640000 , 对应的十进制字符串: 1e18 , 1e18除以该token的精度单位,即1个代币数量 , 所以这里指授权一个代币 Log(exchange.IO("api", tokenAddress, "approve", "spender", "0xde0b6b3a7640000")) }
  • The multicall method is a non-constant method of Uniswap V3 that consumes gas and is used for multi-path token swaps.

    The multicall method 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 multicall method call examples, you can refer to the platform's public "Uniswap V3 Trading Library" template

    Here we use pseudocode to describe some details:

    javascript
    exchange.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: deadline is a parameter of the multicall method, which can be set to (new Date().getTime() / 1000) + 3600, indicating validity within one hour.

    data: data is a parameter of the multicall method, the packed operation data to be executed. Similar to exchange.IO("api", "eth", "send", "toAddress", toAmount), when calling the multicall method, you can also specify the gasLimit/gasPrice/nonce settings for the method call, also described using pseudocode:

    javascript
    exchange.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 the exchange.IO() function.

    You can omit nonce to use the system default value, or not set gasLimit/gasPrice/nonce to use all system default values.

    javascript
    function 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

TypeDescription

string / number / bool / object / array / any (any type supported by the platform)

The exchange.IO("api", ...) function returns the return value of the called smart contract method.

Arguments

NameTypeRequiredDescription

k

string

Yes

The k parameter is used to set the function of exchange.IO(). Setting it to "api" indicates that this function is used for extended API call requests.

address

string

Yes

The address parameter is used to specify the smart contract address.

method

string

Yes

The method parameter is used to specify the smart contract method to be called.

value

number / string

No

The value parameter is used to set the amount of ETH to send. When the stateMutability attribute of the smart contract method to be executed is payable, the value parameter needs to be passed. The "stateMutability":"payable" attribute can be viewed from the ABI. The exchange.IO() function will determine the required parameters based on the stateMutability attribute in the registered ABI. If the stateMutability attribute is nonpayable, there is no need to pass the value parameter.

arg

string / number / bool / any (any type supported by the platform)

No

The arg parameter is used to specify the parameters of the smart contract method to be called.

There may be multiple arg parameters. The type and number of arg parameters depend on the smart contract method to be called.

The exchange.IO("address") function is used to get the wallet address configured for the exchange exchange object.

exchange.IO(k)

Examples

javascript
function main() { Log(exchange.IO("address")) // 打印exchange交易所对象上配置的私钥对应的钱包地址 }

Returns

TypeDescription

string

The exchange.IO("address") function returns the configured wallet address.

Arguments

NameTypeRequiredDescription

k

string

Yes

The k parameter is used to set the function of exchange.IO(). When set to "address", it indicates that the function is used to get the configured wallet address.

The exchange.IO("base", ...) function call is used to set the RPC node address.

exchange.IO(k, address)

Examples

javascript
function main() { var chainRpc = "https://bsc-dataseed.binance.org" e.IO("base", chainRpc) // 切换到BSC链 }

Arguments

NameTypeRequiredDescription

k

string

Yes

The k parameter is used to set the function of exchange.IO(). When set to "base", it indicates that the function is used to switch RPC nodes.

address

string

Yes

The address parameter is used to set the RPC node address.