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

On the FMZ Quant Trading Platform, you can use the exchange.IO() function to call gRPC methods and smart contracts on the TRON blockchain, enabling you to write related strategy code.

Configuration method is similar to Ethereum exchange object configuration, ChainType needs to be selected as TRON. RPC Address defaults to: grpc.trongrid.io:50051, which is the official TRON node address.

TRC20 contract ABI is registered by default, with an underlying mechanism that automatically retrieves contract ABI based on contract address. Manual ABI registration is typically not required, only needed when certain contract ABIs cannot be automatically retrieved.

The method for registering ABI is the same as Ethereum, for example:

javascript
// USDT contract address: TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t let abi = `[{"constant":true,"inputs":[{"name":"who","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}]` // Register balanceOf method exchange.IO("abi", "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", abi)

Use the exchange.IO() function to call TRON RPC methods. For methods requiring signatures, the underlying layer has automatically encapsulated the signing operations. The following lists commonly used methods. For other methods, please refer to the official TRON project documentation.

  • GetAccount
    javascript
    exchange.IO("api", "tron", "GetAccount", "TKCG...") // "TKCG..." is the TRON wallet address, this function returns the account information for the "TKCG..." address.
  • GetAccountResource
    javascript
    exchange.IO("api", "tron", "GetAccountResource", "TKCG...") // Get resources for the specified wallet address, including energy and bandwidth.
  • GetContractABI
    javascript
    exchange.IO("api", "tron", "GetContractABI", "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t") // Get USDT TRC20 contract ABI
  • GetAssetIssueByName
    javascript
    exchange.IO("api", "tron", "GetAssetIssueByName", "TRX") // Get token asset information by token name
  • GetNowBlock
    javascript
    exchange.IO("api", "tron", "GetNowBlock") // Get current block information
  • GetBlockByNum
    javascript
    exchange.IO("api", "tron", "GetBlockByNum", 70624300)
  • GetTransactionByID
    javascript
    exchange.IO("api", "tron", "GetTransactionByID", "05a8fae2cd1cbf36b61d12e219588d25b4826436f055f93388a96e620ec3f3f2") // Get Transaction by transaction hash
  • TRC20ContractBalance
    javascript
    exchange.IO("api", "tron", "TRC20ContractBalance", "TKCG...", "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t") // Get wallet USDT balance, note that the returned data is not precision-processed, for example, returned data: ```6890251``` means ```6.890251 USDT```.
  • TriggerConstantContract
    javascript
    function main() { let ret = exchange.IO("api", "tron", "TriggerConstantContract", "", "TSUUVjysXV8YqHytSNjfkNXnnB49QDvZpx", "token0()", "") // Call the token0() method of the smart contract, TriggerConstantContract is used to call read-only methods let data = exchange.IO("decode", "address", Encode("raw", "raw", "hex", ret["constant_result"][0])) // Decode data return data // data: 0x891cdb91d149f23b1a45d9c5ca78a88d0cb44c18 }
  • TRC20Call
    javascript
    function main() { let ret = exchange.IO("api", "tron", "TRC20Call", "", "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", "0x06fdde03", true, 0) // Use TRC20Call to call read-only method 0x06fdde03 let data = Encode("raw", "raw", "hex", ret.constant_result[0]) return exchange.IO("api", "tron", "ParseTRC20StringProperty", data) // Tether USD }
  • Transfer
    javascript
    exchange.IO("api", "tron", "Transfer", "TWTbn...", "TKCG...", 1000000) // Use Transfer method to transfer TRX, from "TWTbn..." to "TKCG...", 1000000 equals 1 TRX.

When the exchange object is set to Web3 and TRON is selected, encoding/decoding operations remain consistent with Ethereum's Web3 exchange object.

  • encode:
    javascript
    let ret = exchange.IO("encode", "address", "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t") Log(ret) // ret: 000000000000000000000000a614f803b6fd780986a42c78ec9c7f77e6ded13c , encoding the TRON address of USDT token.
  • decode:
    javascript
    let data = "0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000a5465746865722055534400000000000000000000000000000000000000000000" let ret = exchange.IO("decode", "string", data) Log(ret) // ret: Tether USD , similar to the functionality of ParseTRC20StringProperty
  • encodePacked:
    javascript
    let ret = exchange.IO("encodePacked", "address", "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t") Log(ret) // ret: a614f803b6fd780986a42c78ec9c7f77e6ded13c

The switching method is consistent with Web3 Ethereum exchange objects.

Calling smart contract methods on TRON is basically the same as on Ethereum. Here is a specific example demonstrating how to:

  • Call smart contract methods, calling multiple contract methods in a single request:

    javascript
    function main() { let usdtAddress = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t" // token usdt contract address let data1 = exchange.IO("encode", usdtAddress, "name") // call function: name let data2 = exchange.IO("encode", usdtAddress, "decimals") // call function: decimals let data3 = exchange.IO("encode", usdtAddress, "balanceOf", "TKCG...") // call function: balanceOf var data = [] data.push([usdtAddress, data1]) data.push([usdtAddress, data2]) data.push([usdtAddress, data3]) exchange.IO("abi", "TGXuuKAb4bnrn137u39EKbYzKNXvdCes98", `[{"inputs":[{"components":[{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"callData","type":"bytes"}],"internalType":"struct TronMulticall.Call[]","name":"calls","type":"tuple[]"}],"name":"aggregate","outputs":[{"internalType":"uint256","name":"blockNumber","type":"uint256"},{"internalType":"bytes[]","name":"returnData","type":"bytes[]"}],"stateMutability":"view","type":"function"}]`) let ret = exchange.IO("api", "TGXuuKAb4bnrn137u39EKbYzKNXvdCes98", "aggregate", data) Log("name:", exchange.IO("decode", "string", ret["returnData"][0])) Log("decimals:", exchange.IO("decode", "uint8", ret["returnData"][1])) Log("balanceOf:", exchange.IO("decode", "uint256", ret["returnData"][2])) }

    Output:

    log
    Info balanceOf: 6890251 Info decimals: 6 Info name: Tether USD

  • Get wallet address configured for exchange object
    Same usage as Ethereum.

  • Switch blockchain RPC node
    Same usage as Ethereum.

  • Calculate hash value

    javascript
    let algo = "sign" // algo: algorithm/method to use let inputFormat = "string" // inputFormat: input format let outputFormat = "hex" // outputFormat: output format let data = "txHash" // txHash: specific hash value let signature = exchange.IO("hash", algo, inputFormat, outputFormat, data) // returns signature data

    When the algo parameter is set to "sign", it is used for calculating signatures; when set to other algorithm parameters (e.g., "sha256"), the function is equivalent to the Encode() function.