在发明者量化交易平台主要通过exchange.IO()
函数实现区块链相关的各种功能、调用。 以下文档把exchange.IO()
函数根据其功能分别描述。 exchange.IO("abi", ...)
函数的调用方式用于注册ABI。
exchange.IO(k, address, abiContent)
k
true
string
```address```参数用于指定智能合约的地址。
address
true
string
```abiContent```参数用于指定智能合约的```ABI```。
abiContent
true
string
```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只使用了局部的exactOutput方法的内容,完整的abi可以在网上搜索
exchange.IO("abi", routerAddress, abi)
}
调用的智能合约方法如果是标准ERC20方法,则不需要注册。
获取合约的ABI
内容可以通过下面URL获取,只取result
字段,例如:
https://api.etherscan.io/api?module=contract&action=getabi&address=0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45
Threads
exchange.IO("api", "eth", ...)