πŸ“‘ Tronsell Wiki

TRON RPC System β€” Developer Reference

Complete guide to the TRON RPC system. Learn about gRPC and HTTP endpoints, node types, TronGrid, and how to interact with the TRON blockchain programmatically.

πŸ“‘ TRON RPC at a Glance
ProtocolsgRPC + HTTP/JSON
Public APITronGrid
Mainnetapi.trongrid.io
Testnetapi.shasta.trongrid.io
Node TypesFull, Witness, Solidity
Best LibraryTronWeb (JavaScript)

πŸ“‘What is TRON RPC?

TRON RPC (Remote Procedure Call) is the interface that allows developers and applications to interact with the TRON blockchain. It provides a standardized way to query blockchain data, send transactions, deploy smart contracts, and more.

TRON offers two primary RPC protocols:

  • gRPC β€” High-performance, binary-based protocol using Protocol Buffers. Preferred for high-throughput applications.
  • HTTP/JSON (Wallet API) β€” RESTful-like endpoints using JSON. More accessible for web applications and simple integrations.
πŸ’‘ Key Concept

The TRON RPC system is the bridge between your application and the TRON blockchain. Whether you're building a dApp, a wallet, or an analytics tool, you'll interact with TRON through its RPC interfaces.

βš–οΈgRPC vs HTTP API

Feature gRPC HTTP/JSON (Wallet API)
Protocol HTTP/2 + Protocol Buffers HTTP/1.1 + JSON
Performance High (binary serialization) Medium (text serialization)
Ease of Use Complex (requires proto files) Simple (standard HTTP requests)
Language Support Wide (generated clients) Universal (any HTTP client)
Streaming βœ… Built-in ❌ Not native
Best For High-throughput, production apps Web apps, prototyping
πŸ’‘ Recommendation

For most web developers, starting with HTTP/JSON endpoints is the easiest path. For high-performance applications, gRPC is the better choice. TronWeb abstracts both protocols for you.

πŸ—οΈTRON Node Types

TRON has three main types of nodes, each serving a different purpose:

πŸ“¦
Full Node

Stores the entire blockchain history. Validates transactions and blocks. Provides RPC access for queries and transaction submission. The most common node type for developers.

⚑
Witness Node

Produces blocks (Super Representatives). Validates transactions and creates new blocks. Not typically used by developers for RPC access.

πŸ’Ύ
Solidity Node

Stores the current state of the blockchain (balances, smart contract storage). Optimized for quick state queries. Used for reading contract data efficiently.

πŸ’‘ Which Node to Use?

For most RPC operations, Full Nodes are recommended. They provide the most complete set of features and are the primary interface for developers. TronGrid uses Full Nodes behind the scenes.

🌐TronGrid β€” Public API Service

TronGrid is TRON's official public API service. It provides free access to TRON RPC endpoints and load balances requests across multiple full nodes.

  • Mainnet: https://api.trongrid.io
  • Testnet (Shasta): https://api.shasta.trongrid.io
  • gRPC: grpc.trongrid.io (port 50051 for mainnet)
  • Rate limits: Free tier has rate limits. For high-volume applications, consider running your own node or using premium plans.
// Using TronGrid with TronWeb
const TronWeb = require('tronweb');

const tronWeb = new TronWeb({
  fullHost: 'https://api.trongrid.io',
  privateKey: 'your_private_key'
});

// Get account info
const account = await tronWeb.trx.getAccount('TXXX...XXXX');
console.log(account);
⚠️ Rate Limits

TronGrid's free tier has rate limits. If you exceed them, you'll receive HTTP 429 (Too Many Requests) responses. For production applications, consider using a dedicated node or TronGrid's premium plans.

πŸ“‹Key HTTP RPC Endpoints

Here are the most commonly used HTTP RPC endpoints (Wallet API):

Endpoint Method Description
/wallet/getaccount POST Get account information (balance, permissions, etc.)
/wallet/createtransaction POST Create and send a transaction
/wallet/triggersmartcontract POST Execute a smart contract function
/wallet/getblock POST Get block information by number or ID
/wallet/getblockbylatestnum POST Get the latest blocks
/wallet/getaccountresource POST Get account Energy and Bandwidth
/wallet/getnodeinfo GET Get node status and information
/wallet/gettransactioninfobyid POST Get transaction info by ID
πŸ’‘ Using HTTP Endpoints

All HTTP endpoints accept POST requests with a JSON body (except /wallet/getnodeinfo which uses GET). You can test them using tools like cURL or Postman.

⚑gRPC Endpoints

TRON's gRPC API is defined in Protocol Buffers. Key gRPC services:

  • Wallet Service: WalletGrpc β€” Account info, transactions, smart contracts
  • Database Service: DatabaseGrpc β€” Blockchain data queries
  • Monitor Service: MonitorGrpc β€” Network monitoring
  • Solidity Service: SolidityGrpc β€” State queries (balances, contract storage)

gRPC endpoints require Protocol Buffers definitions. TRON provides proto files in its GitHub repository: github.com/tronprotocol/protocol

πŸ’‘ gRPC Setup

To use gRPC, you need to generate client code from TRON's proto files. This can be done for multiple languages (Java, Python, Go, C++, etc.). For JavaScript, TronWeb handles gRPC communication automatically.

πŸ“¦Using RPC with TronWeb

TronWeb is the most popular library for interacting with TRON RPC. It abstracts both HTTP and gRPC endpoints:

  • 1
    Install TronWeb

    npm install tronweb β€” Install via npm or use the CDN version.

  • 2
    Initialize with RPC endpoint

    Pass your TronGrid URL (or custom node) to the TronWeb constructor.

  • 3
    Make RPC calls

    Use TronWeb's methods β€” tronWeb.trx.getAccount(), tronWeb.trx.sendTransaction(), etc.

  • 4
    Handle responses

    TronWeb returns promises and handles the underlying RPC protocol details.

πŸ’‘ TronWeb Advantage

TronWeb automatically handles transaction building, signing, and broadcasting. You don't need to worry about the underlying RPC protocol β€” just use the simple API.

πŸ›‘οΈSecurity Best Practices

  • Never expose private keys: Keep your private keys secure. Use environment variables or secure vaults.
  • Use HTTPS: Always use HTTPS endpoints (TronGrid) to encrypt your RPC communications.
  • Validate inputs: Sanitize and validate all inputs before making RPC calls.
  • Rate limiting: Implement client-side rate limiting to avoid hitting TronGrid limits.
  • Error handling: Handle RPC errors gracefully β€” network issues, timeouts, and rate limits.
  • Consider running your own node: For production applications with high throughput, consider running your own full node for dedicated RPC access.
πŸ” Key Security Rule

Never commit private keys to version control. Use environment variables and secure key management systems. TronWeb supports signing transactions without exposing the private key in code.

❓Frequently Asked Questions

What is TRON RPC?

TRON RPC (Remote Procedure Call) is a set of interfaces that allow developers to interact with the TRON blockchain programmatically. It includes both gRPC and HTTP/JSON endpoints for querying blockchain data, sending transactions, and interacting with smart contracts.

What is the difference between gRPC and HTTP API in TRON?

gRPC is a high-performance RPC framework that uses Protocol Buffers for efficient serialization. It's preferred for high-throughput applications. The HTTP API (wallet endpoints) uses JSON over HTTP and is more accessible for simple integrations and web applications. Both provide the same core functionality.

What is TronGrid?

TronGrid is TRON's public API service that provides access to the TRON blockchain. It offers both gRPC and HTTP/JSON endpoints and load balances requests across multiple full nodes. Developers can use TronGrid endpoints at https://api.trongrid.io (mainnet) and https://api.shasta.trongrid.io (testnet).

How do I make a TRON RPC call?

You can make TRON RPC calls using TronWeb (JavaScript library), direct HTTP requests to wallet endpoints, or gRPC client libraries. For example, a simple HTTP POST to /wallet/getaccount can retrieve account information. TronWeb handles the complexity of building and sending requests.

Should I use TronGrid or run my own node?

TronGrid is convenient and free for moderate usage. For production applications with high throughput, running your own full node is recommended. It gives you dedicated resources, no rate limits, and full control over the RPC environment.

⚑ Build with Tronsell Energy

Integrate Tronsell Energy into your dApps for zero-fee USDT transfers. Simple API, instant delivery, no staking required.