Tron API Overview

Welcome to the Tron API Quickstart and Reference Guide. This guide provides everything you need to start building on Tron using dRPC’s JSON-RPC API. Whether you're retrieving account balances, fetching block details, executing transactions, or estimating gas fees, this comprehensive guide will help you integrate Tron seamlessly into your applications.

This page includes:

  • A Quickstart Guide to help you set up and make your first Tron API request.
  • A detailed list of all Tron API methods, categorized for easy reference.

Scroll to API Methods

Tron API Quickstart#

To get started with building on Tron using dRPC's Tron RPC API, follow these steps:

1. Create a dRPC Account or Use Public Tron RPC endpoints

By signing up for a free dRPC account, you can access their Premium Tron RPC endpoints.

Public endpoints:

HTTPS

https://tron.drpc.org/

2. Set Up Your Development Environment

RPC can be requested in various ways (opens in a new tab). In this example, we are going to use Node.js. Ensure you have Node.js (opens in a new tab) and npm installed on your system. You can verify their installation by running:

node -v
npm -v

If not installed, download and install them from the official Node.js website (opens in a new tab).

3. Initialize Your Project

Create a new directory for your project and initialize it:

mkdir tron-drpc-quickstart
cd tron-drpc-quickstart
npm init --yes

4. Install Axios

Axios is a popular HTTP client for making API requests. Install it using npm:

npm install axios

5. Obtain dRPC Endpoint

Log in to your dRPC account and navigate to the Tron RPC endpoints section. Copy the HTTPS endpoint URL for the tron Mainnet.

6. Write Your First Script

Create an index.js file in your project directory and add the following code:

const axios = require('axios');
 
const url = 'https://lb.drpc.org/ogrpc?network=tron&dkey=YOUR_DRPC_API_KEY';
 
const payload = {
  jsonrpc: '2.0',
  id: 1,
  method: 'eth_blockNumber',
  params: []
};
 
axios.post(url, payload)
  .then(response => {
    console.log('The latest block number is', parseInt(response.data.result, 16));
  })
  .catch(error => {
    console.error('Error fetching block number:', error);
  });

Replace ‘https://lb.drpc.org/ogrpc?network=tron&dkey=YOUR_DRPC_API_KEY' with the actual endpoint URL you obtained from dRPC.

7. Run Your Script

Execute your script using Node.js:

node index.js

You should see the latest Tron block number printed in your console.

Additional Information

dRPC offers various features such as high performance nodes, access to multiple chains. For more details, visit their Tron API documentation (opens in a new tab).

By following these steps, you can start building on Tron using dRPC's reliable and efficient RPC endpoints.

Tron JSON RPC API Methods#

These endpoints allow to retrieve information about blocks, transactions, balances, logs, and more, facilitating efficient blockchain development and integration.

Accounts info#

Retrieves data about an account’s on-chain storage, balance, and contract code.

eth_accounts : Retrieves a list of accounts controlled by the client.
eth_getBalance : Fetches the balance of an account.
eth_getCode : Returns the smart contract code stored at an address.
eth_getProof : Provides a Merkle proof for an account's state.
eth_getStorageAt : Retrieves data stored at a specific storage slot of an account.

Blocks info#

Retrieves detailed information about a specific block using its number or hash

eth_blockNumber : Retrieves the most recent block number.
eth_getBlockByHash : Fetches block details by hash.
eth_getBlockByHash#full : Returns full block details by hash.
eth_getBlockByNumber : Retrieves block data by number.
eth_getBlockByNumber#full : Fetches full block details by number.
eth_newBlockFilter : Available only on paid tier. Creates a filter for new blocks.
eth_getBlockReceipts : Fetches receipts for all transactions in a block.
eth_getBlockTransactionCountByHash : Retrieves the number of transactions in a block by its hash.
eth_getBlockTransactionCountByNumber : Returns the number of transactions in a block by its number.

Chain info#

Gathers essential details about the tron network and its protocol settings.

eth_chainId : Retrieves the network's chain ID.
eth_protocolVersion : Returns the protocol version of the client.
net_listening : Checks if the node is listening for connections.
net_version : Provides the current network version.
net_peerCount : Returns the number of connected peers.
eth_syncing : Indicates whether the node is syncing.
eth_hashrate : Provides the network's mining hashrate.

Debug and trace#

Available only on paid tier. Contains advanced debugging and tracing tools.

trace_filter : Filters trace data based on specific criteria.
trace_rawTransaction : Replays a raw transaction for debugging.
trace_block : Traces all transactions in a block.
trace_replayBlockTransactions : Replays transactions within a block for analysis.
debug_traceBlockByHash : Traces a block's execution by hash.

Event logs#

Extracts logs related to smart contract events like token transfers or ownership changes.

eth_getLogs : Retrieves logs from the blockchain based on specified filter criteria.
eth_newFilter : Available only on paid tier. Creates a new filter to track specific events.
eth_getFilterChanges : Available only on paid tier. Retrieves changes for an active filter since its last check.
eth_uninstallFilter : Removes an installed filter.
eth_getFilterLogs : Available only on paid tier. Fetches logs from an active filter.

Executing transactions#

Enables the sending of ETH, contract interaction, or writing data to the chain.

eth_call : Executes a read-only call to a smart contract without changing the blockchain state.
eth_sendRawTransaction : Broadcasts a raw, signed transaction to the blockchain for execution.

Gas estimation#

Estimates gas prices and consumption for transactions.

eth_feeHistory : Retrieves historical gas prices over a range of blocks.
eth_estimateGas : Estimates the gas required to execute a transaction.
eth_gasPrice : Returns the current gas price on the network.
eth_createAccessList : Generates an access list for transaction optimization.
eth_maxPriorityFeePerGas : Retrieves the maximum priority fee for gas.

Getting uncles#

Retrieves information about uncle blocks (blocks rejected by the network).

eth_getUncleByBlockHashAndIndex : Fetches details of an uncle block by its hash and index.
eth_getUncleByBlockNumberAndIndex : Retrieves an uncle block by its block number and index.
eth_getUncleCountByBlockHash : Returns the count of uncles for a specific block hash.
eth_getUncleCountByBlockNumber : Retrieves the number of uncles for a block number.

Mining#

Consists of methods that provide information related to the mining.

eth_coinbase : Returns the address of the current coinbase (mining reward recipient).
eth_mining : Indicates whether the node is currently mining blocks.

Transactions info#

Accesses transaction details, such as their state, count, or receipts.

eth_getTransactionByHash : Fetches transaction details using its hash.
eth_getTransactionCount : Returns the number of transactions sent from an address.
eth_getTransactionReceipt : Retrieves the receipt of a processed transaction.
eth_newPendingTransactionFilter : Available only on paid tier. Sets up a filter to monitor pending transactions.
eth_getTransactionByBlockHashAndIndex : Retrieves a transaction by block hash and index.
eth_getTransactionByBlockNumberAndIndex : Fetches a transaction by block number and index. \

Web3#

Provides utility functions to interact with the blockchain.

web3_clientVersion : Returns the version of the client used by the node.
web3_sha3 : Computes the Keccak-256 (SHA3) hash of the provided input data.

Tron HTTP API Methods#

Account info#

Returns data about an account's balance, permissions, resources, and multi-signature status on the Tron blockchain.

getaccount : Returns account details such as balance, permissions, and resources for a given address.
getaccountnet : Returns the bandwidth usage and limits for a given account.
getaccountresource : Returns the energy and bandwidth resource usage and limits for a given account.
getaccountbalance : Returns the TRX balance of an account at a specific block height.
createaccount : Creates a new account on the Tron network, activated by an existing account.
updateaccount : Updates the account name associated with a Tron address.
accountpermissionupdate : Updates the owner, witness, and active permissions of a multi-signature account.
validateaddress : Validates whether a given string is a properly formatted Tron address.
getapprovedlist : Returns the list of approving addresses for a pending multi-signature transaction.
getsignweight : Returns the current signature weight and threshold status of a multi-signature transaction.

Blocks info#

Retrieves detailed information from a specified Tron block, including transactions and block header data.

getnowblock : Returns the most recent confirmed block on the Tron blockchain.
getblock : Returns block details by block number, block hash, or the latest block if no parameter is given.
getblockbyid : Returns block details for a specific block hash (block ID).
getblockbylatestnum : Returns a list of the most recent blocks up to a specified count.
getblockbylimitnext : Returns a range of blocks between a start and end block number.
getblockbynum : Returns block details for a specific block number.
getblockbalance : Returns the aggregated balance changes for all accounts within a specific block.

Transactions info#

Retrieves data on individual transactions, and creates or broadcasts new ones.

gettransactionbyid : Returns transaction details for a given transaction hash (ID).
gettransactioncountbyblocknum : Returns the number of transactions included in a specific block.
gettransactionfrompending : Returns a pending transaction from the node's transaction pool by its hash.
gettransactioninfobyblocknum : Returns execution results and receipts for all transactions in a specific block.
gettransactioninfobyid : Returns the execution result, receipt, and logs for a confirmed transaction by its hash.
gettransactionlistfrompending : Returns the list of transaction hashes currently in the node's pending transaction pool.
createtransaction : Creates an unsigned TRX transfer transaction between two addresses.
broadcasttransaction : Broadcasts a signed transaction to the Tron network.
broadcasthex : Broadcasts a signed transaction supplied as a raw hex string to the Tron network.

Smart contracts#

Deploys, calls, and inspects smart contracts on the Tron Virtual Machine (TVM).

deploycontract : Creates an unsigned transaction to deploy a smart contract to the Tron network.
triggersmartcontract : Creates an unsigned transaction that calls a function on a deployed smart contract.
triggerconstantcontract : Executes a read-only smart contract call without broadcasting a transaction or consuming energy.
getcontract : Returns the bytecode and metadata of a deployed smart contract by address.
getcontractinfo : Returns extended contract information, including ABI and source metadata, by address.
clearabi : Creates a transaction that clears the stored ABI of a smart contract.
estimateenergy : Estimates the energy required to execute a smart contract call before sending it.
updatesetting : Updates the user resource percentage (consume_user_resource_percent) of a smart contract.
updateenergylimit : Updates the origin energy limit of a deployed smart contract.

Asset issue (TRC10)#

Issues, queries, and transfers native TRC10 tokens.

createassetissue : Issues a new TRC10 token on the Tron network.
getassetissuebyaccount : Returns the TRC10 token issued by a specific account.
getassetissuebyid : Returns TRC10 token details by its numeric asset ID.
getassetissuebyname : Returns TRC10 token details by its token name.
getassetissuelist : Returns the full list of TRC10 tokens issued on the network.
getassetissuelistbyname : Returns all TRC10 tokens that share a given token name.
getpaginatedassetissuelist : Returns a paginated list of TRC10 tokens using offset and limit parameters.
participateassetissue : Creates a transaction to purchase a TRC10 token during its issuance period.
transferasset : Creates a transaction to transfer a TRC10 token between two addresses.
unfreezeasset : Creates a transaction to unfreeze TRX that was frozen for TRC10 issuance bandwidth.
updateasset : Updates the description, URL, and limits of an issued TRC10 token.

Resource management#

Manages bandwidth and energy through freezing, staking, and delegation (Stake 1.0 and Stake 2.0).

freezebalance : Creates a transaction to freeze TRX in exchange for bandwidth or energy (legacy model).
freezebalancev2 : Creates a transaction to freeze TRX for bandwidth or energy under the Stake 2.0 model.
unfreezebalance : Creates a transaction to unfreeze previously frozen TRX under the legacy staking model.
unfreezebalancev2 : Creates a transaction to unstake TRX and start the unfreeze withdrawal period under Stake 2.0.
cancelallunfreezev2 : Cancels all pending Stake 2.0 unfreeze operations for an account and re-stakes the TRX.
delegateresource : Creates a transaction to delegate bandwidth or energy from one account to another.
undelegateresource : Creates a transaction to reclaim previously delegated bandwidth or energy.
getdelegatedresource : Returns the resource delegation details between two specific accounts.
getdelegatedresourceaccountindex : Returns the list of accounts an address has delegated resources to or from (legacy index).
getdelegatedresourceaccountindexv2 : Returns the Stake 2.0 list of accounts an address has delegated resources to or from.
getdelegatedresourcev2 : Returns the Stake 2.0 resource delegation details between two specific accounts.
getavailableunfreezecount : Returns the number of remaining unfreeze operations available for an account under Stake 2.0.
getcandelegatedmaxsize : Returns the maximum amount of a resource an account can still delegate to others.
getcanwithdrawunfreezeamount : Returns the amount of unfrozen TRX currently available for withdrawal from an account.
withdrawexpireunfreeze : Creates a transaction to withdraw TRX whose Stake 2.0 unfreeze waiting period has expired.
getbandwidthprices : Returns the historical and current price schedule for bandwidth on the network.
getenergyprices : Returns the historical and current price schedule for energy on the network.
withdrawbalance : Creates a transaction to withdraw available block reward rewards for a witness account.
getburntrx : Returns the total amount of TRX burned by the network from transaction fees.

Witnesses and voting#

Manages Super Representative (witness) registration, voting, and reward distribution.

createwitness : Creates a transaction to register an account as a Super Representative (witness) candidate.
updatewitness : Updates the URL associated with a registered witness account.
votewitnessaccount : Creates a transaction to cast votes for one or more Super Representative candidates.
listwitnesses : Returns the full list of Super Representatives and candidates with their vote counts.
getpaginatednowwitnesslist : Returns a paginated list of current Super Representatives using offset and limit parameters.
getBrokerage : Returns the brokerage (commission) ratio a witness keeps from voting rewards.
getReward : Returns the unwithdrawn voting reward balance for an account.
updateBrokerage : Creates a transaction to update the brokerage ratio a witness keeps from voting rewards.

Network and governance#

Manages network parameter proposals and returns chain-wide configuration data.

proposalapprove : Creates a transaction for a witness to approve or withdraw approval of a network parameter proposal.
proposalcreate : Creates a transaction to propose a change to a network configuration parameter.
proposaldelete : Creates a transaction to cancel a previously submitted network parameter proposal.
listproposals : Returns the full list of network parameter proposals and their statuses.
getpaginatedproposallist : Returns a paginated list of network parameter proposals using offset and limit parameters.
getproposalbyid : Returns the details and vote status of a specific network parameter proposal.
getchainparameters : Returns the current values of all configurable network parameters.
getnextmaintenancetime : Returns the Unix timestamp of the next network maintenance (vote-counting) cycle.

Node info#

Returns information about the queried node itself and its peers.

getnodeinfo : Returns version, configuration, and peer connection details for the queried node.
listnodes : Returns the list of peer nodes currently connected to the queried node.
getpendingsize : Returns the current number of transactions waiting in the node's pending pool.