Exchange/Wallet integrate with the TRON network

The following questions are generally considered when wallets and exchanges integrate with the TRON network:

  1. How to determine an address has asset transferred in time?
  2. How to get historical transaction records of an address?
  3. How to query asset balance and transfer assset?

The above requirements can be achieved by accessing the TronGrid service or building a TRON full node. Due to limited resources, the TronGrid service will set the access frequency and daily total limit: 15QPS and 100,000 daily requests. So it is recommended to build a full node if you have high access frequency and total requirements.

In addition to providing all the APIs of the full node, the TronGrid API service also provides some more convenient query API, such as querying the historical transaction records of an account. By continuously polling such an API, you can monitor the real-time transfer in and out of an address, which is a great help for wallet and exchange integration.

After building a full node, the historical transaction records of an account can be obtained by parsing historical blocks, and the outgoing and incoming transactions of an address can be monitored in real time by parsing the latest block. Full nodes also provide APIs for transferring and broadcasting transactions.

Deploy a Fullnode of TRON Network

If you want to build your own node, please refer to the Deploy A Node tutorial to complete the node deployment.

Configure the Fullnode

Before starting the node, please check the node configuration file main_net_config.conf. Generally, you need to focus on the following configuration items:

  • vm.supportConstant
    Whether the node supports calling read-only contract functions. It is recommended to set it to true, because the business scenarios of general exchanges and wallets involve querying the balance of TRC20 tokens. To query the balance of TRC20 tokens, you must call the balanceOf read-only function of the TRC20 token contract.
  • vm.saveInternalTx
    Whether the node stores internal transactions. Calling other contracts in the contract or transferring asset from contract to other addresses is called internal transactions. It is recommended to set it to true, because the business scenarios of exchanges and wallets involve block parsing. Only this option enabled ensures all transaction records be obtained.
  • vm.maxTimeRatio
    The node's tolerance for transaction timeout when verifying smart contract transactions. If the configuration of the machine is below the recommended configuration, it is recommended to set it to 20.0 or higher, otherwise it may cause the node to stop synchronizing.

Query Balance

The following table lists the example query APIs to query TRX, TRC10 and TRC20 token balances.

FunctionInterfaceExample
Query TRX Balance/wallet/getaccountTRX Balance
Query TRC10 Balance/wallet/getaccountTRC10 Balance
Query TRC20 Balance/wallet/triggerconstantcontractTRC20 Balance

Transfer

The process of sending a transfer transaction includes three steps: creating a transaction, signing and broadcasting the transaction. For the life cycle of the transaction, please refer to the Transaction chapter.

The following table lists APIs and examples for creating transfering TRX, TRC10, and TRC20 transactions. And SDKs in different languages include offline signing methods.

Parse blocks to get transaction records

The historical transaction records of an account can be obtained by parsing historical blocks, and the outgoing and incoming transactions of an address can be monitored in real time by parsing the latest blocks.

You can refer to the following steps to parse blocks to obtain TRX, TRC10 and TRC20 historical records:

  1. Get block information
    Get block information from the solidified block according to the block number: /walletsolidity/getblockbynum

  2. Get transactions from the block.

  3. Go through all the transactions and get the raw_data.contract[0] of each transaction.

  4. Check the type of transaction based on raw_data.contract[0].type:

    • TRX Transfer Transaction: raw_data.contract[0].type == transferContract
      Check if the receiving address and amount meet the entry criteria.

      • raw_data.contract[0].parameter.value.owner_address is the transfer address
      • raw_data.contract[0].parameter.value.to_address is the recipient address
      • raw_data.contract[0].parameter.value.amount is the amount of the transfer
    • TRC10 Transfer Transaction: raw_data.contract[0].type == TransferAssetContract
      Check if the token id, receiving address and amount meet the entry criteria.

      • raw_data.contract[0].parameter.value.owner_address is the transfer address
      • raw_data.contract[0].parameter.value.to_address is the recipient address
      • raw_data.contract[0].parameter.value.asset_name is TRC10 token id
      • raw_data.contract[0].parameter.value.amount is the amount of the transfer
    • Smart Contract Transaction: raw_data.contract[0].type == TriggerSmartContract
      One smart contract transaction can contain TRC20 Token Transfer, TRX transfer, and TRC10 Token Transfer. The below process shows how to proceed with a smart contract transaction.

      1. Check whether the transaction is successful, skip the transaction if it is not successful.
        Call /walletsolidity/gettransactioninfobyid to check whether receive.result == SUCCESS, if yes, the transaction is executed successfully.
      2. Determine whether the transaction contains TRC20 transfers:
        call /walletsolidity/gettransactioninfobyid to check whether the smart contract transaction contains "Transfer" events, If yes, parse all the events (There may be multiple TRC20 transfers in a smart contract transaction) one by one to get the contract address, transfer address, and amount in the event. Event parsing rules please refer to Here.
      3. TRX/TRC10 Token Transfer in smart contract transaction: call /walletsolidity/gettransactioninfobyid, check whether the smart contract transaction contains internal transactions, if yes, then traverse the internal transactions:
        • If internal_transactions.callValueInfo != null & internal_transactions.callValueInfo[i].tokenId == null means it is a TRX transfer that is performed in the contract. Example transaction
          • internal_transactions.caller is the transfer address
          • internal_transactions.transferTo_address is the recipient address
          • internal_transactions.callValueInfo[i].callValue is the amount of the transfer
        • If internal_transactions.callValueInfo != null & internal_transactions.callValueInfo[0].tokenId != null means that a TRC10 transfer was made in the contract. Example transaction
          • internal_transactions.caller is the transfer address
          • internal_transactions.transferTo_address is the recipient address
          • internal_transactions.callValueInfo[i].tokenId is TRC10 token ID
          • internal_transactions.callValueInfo[i].callValue is the transfer amount

Use TronGrid API Service

The TronGrid API service provides all the APIs of the fullnode of the TRON network and its unique extension API. However, in order to ensure the reasonable allocation of requested resources, all requests need to provide API Key. Domain names starting with https://api.shasta.trongrid.io/v1 are all v1 extension APIs. For details about v1 extension APIs, please refer to Trongrid v1 API

TronGrid API Endpoint

Mainnet:https://api.trongrid.io
Shasta testnet:https://api.shasta.trongrid.io
Nile testnet: https://nile.trongrid.io

Query Balance

The following table lists the query APIs and examples for querying TRX, TRC10 and TRC20 token balances.

Transfer

The process of sending a transfer transaction includes three steps: creating a transaction body, signing, and broadcasting the transaction. For the life cycle of the transaction, please refer to the Transaction chapter.

The following table lists APIs for creating TRX, TRC10, and TRC20 token transfer transactions, as well as signing and broadcasting examples. SDKs in different languages include offline signing methods.

Get transaction history

The TronGrid v1 extension API supports querying the historical transaction records of an account. By continuously querying the historical transaction records of an address, it is also possible to monitor the real-time transfer in and out transactions of an address.

The following table lists the APIs for querying the transfer records of TRX, TRC10 and TRC20 tokens on an address.

FunctionAPIDescription
Query account history TRX and TRC10 transaction recordsv1/accounts/{address}/transactions?only_confirmed=trueThe return value contains TRX and TRC10 transaction records. The transaction type is distinguished by the type field in the transaction. TransferContract represents TRX transfer, TransferAssetContract represents TRC10 record
Query account history TRC20 transaction recordsv1/accounts/{address}/transactions/trc20?only_confirmed=trueThe return value contains TRC20 transaction records