TRON access via Ethereum JSON-RPC API

TRON's /jsonrpc endpoint accepts Ethereum methods such as eth_getBalance and eth_call, but only with hex addresses, and it can't broadcast transactions.

Tatum lets you call the TRON blockchain with Ethereum-compatible JSON-RPC methods such as eth_getBalance, eth_call and eth_getLogs at https://tron-mainnet.gateway.tatum.io/jsonrpc. This is useful when you integrate TRON into systems or libraries built for Ethereum. Pass addresses in hex, not base58 (T...), read state at latest only, and broadcast transactions through TRON's HTTP API.

Symptom

A call to the TRON JSON-RPC endpoint returns HTTP 200 OK with an error object in the body, for example after passing a base58 address to eth_getBalance:

{
  "id": 1,
  "jsonrpc": "2.0",
  "error": {
    "code": -32602,
    "message": "exception decoding Hex string: invalid characters encountered in Hex string",
    "data": "{}"
  }
}

The most common errors and what triggers them:

Error messageCodeTriggered by
exception decoding Hex string: invalid characters encountered in Hex string-32602A base58 address that starts with T
QUANTITY not supported, just support TAG as latest-32602A block number instead of latest in a state read
the method eth_sendRawTransaction does not exist/is not available-32601Broadcasting a transaction over JSON-RPC

Cause

TRON's Ethereum-compatible JSON-RPC endpoint supports a range of standard EVM methods, such as eth_getBalance and eth_call, but it runs on a TRON node, not an Ethereum node. Only supported Ethereum-compatible methods work, and they differ from Ethereum in a few ways:

  • Hex addresses only. Methods accept a 20-byte Ethereum-style address (0x...) or a 21-byte TRON address that starts with 41. Base58check addresses that start with T are rejected.
  • latest only for state reads. eth_getBalance, eth_getStorageAt, eth_getCode and eth_call read the latest block only.
  • No broadcast. TRON transactions use a Protobuf format instead of Ethereum's RLP encoding, and the JSON-RPC interface can't broadcast them.
  • Balances in SUN. eth_getBalance returns the TRX balance in SUN (1 TRX = 1,000,000 SUN), not in wei.

Solution

  1. Convert the address to hex. Decode the base58check T... address: the result is 21 bytes that start with 41. Drop the 41 and add the 0x prefix. For example, TNAfStqVaTak2mH81fbnuHVKTfy7bbcqRF becomes 0x85cC29184B18AE2909b85668DA996ACFA253F4e2.

  2. Send the call with latest to the JSON-RPC endpoint, with your API key in the x-api-key header. Find the Mainnet, Shasta and Nile URLs on TRON RPC endpoints.

    curl --location 'https://tron-mainnet.gateway.tatum.io/jsonrpc' \
      --header 'Content-Type: application/json' \
      --header 'x-api-key: {YOUR_API_KEY}' \
      --data '{
        "jsonrpc": "2.0",
        "method": "eth_getBalance",
        "params": ["0x85cC29184B18AE2909b85668DA996ACFA253F4e2", "latest"],
        "id": 1
      }'

    The result is the balance in SUN as a hex number. For example, 0x79064d is 7,931,469 SUN, or 7.931469 TRX:

    {"id": 1, "jsonrpc": "2.0", "result": "0x79064d"}
  3. Broadcast through the HTTP API. Send signed transactions to https://tron-mainnet.gateway.tatum.io/wallet/broadcasttransaction (JSON) or /wallet/broadcasthex (hex). For any other feature that JSON-RPC doesn't cover, use the native TRON APIs listed in TRON REST API endpoints.

FAQ

What is the TRON RPC URL?

On Tatum, the TRON Mainnet JSON-RPC URL is https://tron-mainnet.gateway.tatum.io/jsonrpc and the HTTP API base URL is https://tron-mainnet.gateway.tatum.io/wallet. Both take your API key in the x-api-key header.

Which Ethereum methods does TRON support?

The endpoint supports eth_*, net_* and web3_* methods plus TRON's buildTransaction. See the full list in TRON JSON-RPC methods.

What is the TRON chain ID?

TRON Mainnet's chain ID is 728126428 (0x2b6653dc), as returned by eth_chainId.

Still stuck?

Report the issue to support with the full request, the response and its x-request-id.


Did this page help you?