Type/to search
Welcome to FMZ Quant Trading Platform
Programming Languages
JavaScript
TypeScript
Python
C++
MyLanguage
PINE Language
Blockly Visual Programming
Workflow
Key Security
Live Trading
Strategy Library
Docker
Deploy Docker
One-Click Docker Rental
Manual Deployment of Bot
Docker Operation Precautions
Global IP Address Specification
Command Line Parameters for Bot Program
Live Trading Data Migration
Docker Monitor
Exchange
Strategy Editor
Backtesting System
Strategy Entry Functions
Strategy Framework and API Functions
Template Library
Strategy Parameters
Interactive Controls
Options Trading
C++ Strategy Writing Guide
JavaScript Strategy Writing Guide
Web3
Built-in Libraries
Extended API Interface
MCP Service
Trading Terminal
Data Explorer
Alpha Factor Analysis Tool
General Protocol
Debugging Tool
Remote Editing
Import and Export of Complete Strategies
Multi-language Support
Live Trading and Strategy Grouping
Live Trading Display
Strategy Sharing and Renting
Live Trading Message Push
Common Causes of Live Trading Errors and Abnormal Exits
Exchange-Specific Notes

The following are examples of smart contract method calls.

  • decimals
    decimals method is a constant method of ERC20 (no need to register ABI when calling standard ERC20 methods in FMZ quantitative strategy code), which does not consume gas and can query the precision data of a token.
    The decimals method has no parameters and returns the precision data of the token.

    javascript
    function main(){ var tokenAddress = "0x111111111117dC0aa78b770fA6A738034120C302" // Token contract address, the token in this example is 1INCH Log(exchange.IO("api", tokenAddress, "decimals")) // Query and print that the precision exponent of 1INCH token is 18 }
  • allowance
    allowance method is a constant method of ERC20, which does not consume gas and can query the authorization amount of a token for a certain contract address.
    The allowance method requires 2 parameters, the first parameter is the wallet address, and the second parameter is the authorized address. The return value is the authorization amount of the token.

    javascript
    function main(){ // Token contract address, the token in this example is 1INCH var tokenAddress = "0x111111111117dC0aa78b770fA6A738034120C302" var owner = "" var spender = "" // For example, if the query returns 1000000000000000000, divide by the token's precision unit 1e18 to get that the wallet bound to the current exchange object has authorized 1 1INCH to the spender address Log(exchange.IO("api", tokenAddress, "allowance", owner, spender)) }

    owner: Wallet address, needs to be filled with the specific address in actual use.
    spender: Authorized contract address, needs to be filled with the specific address in actual use, for example, it can be the Uniswap V3 router v1 address.

  • approve
    approve method is a non-constant method of ERC20, which consumes gas and is used to authorize a certain contract address with the operation amount of token.
    The approve method requires 2 parameters, the first parameter is the authorized address, and the second parameter is the authorization amount. The return value is txid.

    javascript
    function main(){ // Token contract address, the token in this example is 1INCH var tokenAddress = "0x111111111117dC0aa78b770fA6A738034120C302" var spender = "" var amount = "0xde0b6b3a7640000" // Hexadecimal string of authorization amount: 0xde0b6b3a7640000, corresponding decimal string: 1e18, 1e18 divided by the token's precision unit equals 1 token amount, so this authorizes one token Log(exchange.IO("api", tokenAddress, "approve", spender, amount)) }

    spender: Authorized contract address, needs to be filled with the specific address in actual use, for example, it can be the Uniswap V3 router v1 address.
    amount: Authorization amount, represented here as a hexadecimal string. The corresponding decimal value is 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 the form of methodId, for example: "0x571ac8b0". It can also be written as the complete standard method name, for example: "approve(address,uint256)".

  • multicall
    multicall method is a non-constant method of Uniswap V3, which consumes gas and is used for batch token swaps.
    The multicall method may have multiple parameter passing methods, you can check the ABI containing this method for details. The ABI needs to be registered before calling this method. The return value is txid.

    For specific multicall method call examples, you can refer to the platform's public "Uniswap V3 Trading Library" template

    javascript
    function main() { var ABI_Route = "" var contractV3SwapRouterV2 = "" var value = 0 var deadline = (new Date().getTime() / 1000) + 3600 var data = "" exchange.IO("abi", contractV3SwapRouterV2, ABI_Route) exchange.IO("api", contractV3SwapRouterV2, "multicall(uint256,bytes[])", value, deadline, data) }

    ABI_Route: ABI of Uniswap V3's router v2 contract, needs to be filled according to actual situation.
    contractV3SwapRouterV2: Uniswap V3's router v2 address, needs to be filled with the specific address in actual use.
    value: Amount of ETH to transfer, set to 0 if the tokenIn token for the swap operation is not ETH, needs to be filled according to actual situation.
    deadline: Can be set to (new Date().getTime() / 1000) + 3600, indicating validity within one hour.
    data: Packed operation data to be executed, needs to be filled according to actual situation.

    You can also specify gasLimit/gasPrice/nonce settings for method calls:

    javascript
    exchange.IO("api", contractV3SwapRouterV2, "multicall(uint256,bytes[])", value, deadline, data, {gasPrice: 5000000000, gasLimit: 21000})

    You can set {gasPrice: 5000000000, gasLimit: 21000, nonce: 100} parameters according to specific needs, 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.

    Note that the stateMutability attribute of the multicall(uint256,bytes[]) method in the example is payable, which requires passing the value parameter.
    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.