π‘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.
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 |
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:
Stores the entire blockchain history. Validates transactions and blocks. Provides RPC access for queries and transaction submission. The most common node type for developers.
Produces blocks (Super Representatives). Validates transactions and creates new blocks. Not typically used by developers for RPC access.
Stores the current state of the blockchain (balances, smart contract storage). Optimized for quick state queries. Used for reading contract data efficiently.
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.
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 |
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
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 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.
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.