๐ RPC Infrastructure Overview
TRON's RPC (Remote Procedure Call) infrastructure is the gateway for applications, developers, and users to interact with the blockchain. It provides a standardized interface for querying blockchain data, submitting transactions, and interacting with smart contracts.
The RPC layer sits on top of the full node and exposes two primary interfaces:
- HTTP JSON-RPC โ REST-like endpoints on port 8090 for simple, language-agnostic access.
- gRPC โ High-performance, strongly-typed RPC on port 50051 using Protocol Buffers.
RPC infrastructure is critical for dApps, exchanges, wallets, and analytics platforms. It must be reliable, scalable, and secure to handle production workloads.
๐งฉ RPC Infrastructure Components
Port 8090. Simple REST endpoints for wallet, contract, and block operations. Easy to integrate with any programming language.
Port 50051. High-performance RPC with Protocol Buffers. Supports streaming and bidirectional communication.
Distributes RPC traffic across multiple nodes. Supports round-robin, least connections, and health checking.
Provides authentication, rate limiting, request logging, and TLS termination for RPC endpoints.
๐ HTTP JSON-RPC Endpoints
The HTTP JSON-RPC API is the most accessible way to interact with a TRON node. All endpoints accept POST requests with a JSON body.
Common HTTP Endpoints
| Endpoint | Method | Description |
|---|---|---|
| /wallet/getnowblock | POST | Get the current block header |
| /wallet/getaccount | POST | Get account balance and resources |
| /wallet/createtransaction | POST | Create a transfer transaction |
| /wallet/broadcasttransaction | POST | Broadcast a signed transaction |
| /wallet/triggersmartcontract | POST | Execute a smart contract method |
| /contract/deploycontract | POST | Deploy a smart contract |
HTTP JSON-RPC is easier to use for quick prototyping and debugging. For production applications with high throughput, gRPC is recommended for its performance and type safety.
โก gRPC Infrastructure
gRPC is a modern RPC framework developed by Google. TRON uses gRPC for its high-performance API, offering significant advantages over HTTP JSON-RPC.
gRPC Features
- Protocol Buffers โ Binary serialization for smaller payloads and faster parsing.
- Streaming โ Support for server-streaming, client-streaming, and bidirectional streaming.
- Type Safety โ Strongly-typed interfaces generated from .proto files.
- Multiplexing โ Multiple calls over a single connection.
gRPC Services
- Wallet โ Account, transaction, and block operations.
- Contract โ Smart contract deployment and execution.
- Network โ Node status, peer information.
- Database โ Historical data queries.
gRPC can handle 10x-100x more requests per second than HTTP JSON-RPC for the same hardware, making it the preferred choice for production RPC infrastructure.
โ๏ธ Load Balancing & High Availability
For production RPC infrastructure, a single node is a single point of failure. Load balancing distributes traffic across multiple nodes, ensuring reliability and scalability.
Load Balancing Strategies
| Strategy | Description | Pros | Cons |
|---|---|---|---|
| Round Robin | Distributes requests evenly across nodes | Simple, fair distribution | Does not account for node load |
| Least Connections | Sends requests to the node with fewest active connections | Better load distribution under varying loads | Requires connection tracking |
| Health Check | Routes only to healthy nodes | Prevents routing to dead or lagging nodes | Adds monitoring overhead |
| Geo-aware | Routes to nodes closest to the client | Reduces latency | Requires geo-location data |
Load Balancer Tools
- Nginx โ HTTP/gRPC load balancing with health checks.
- HAProxy โ High-performance TCP and HTTP load balancing.
- Envoy โ Modern edge proxy with advanced traffic management.
- Cloud Load Balancers โ AWS NLB, GCP Cloud Load Balancing.
For high availability, deploy at least 3โ5 full nodes behind a load balancer. This provides redundancy and allows you to perform maintenance without downtime.
๐ RPC Security
RPC endpoints are a primary attack vector. Securing them is critical for production deployments.
Encrypt all RPC traffic with TLS. Use valid certificates from a trusted CA. gRPC requires HTTP/2 over TLS.
Limit requests per IP or API key to prevent abuse and DDoS attacks. Implement at the gateway level.
Use API keys or JWT tokens for authenticated endpoints. Restrict access to trusted applications.
Restrict RPC access to specific IP ranges or VPNs for internal services.
โ
Enable TLS for all RPC traffic
โ
Implement rate limiting
โ
Use API keys for authentication
โ
Restrict IP ranges where possible
โ
Enable access logging and monitoring
โ
Regularly update TLS certificates
๐ Scaling RPC Infrastructure
As demand grows, your RPC infrastructure must scale. Here are strategies for scaling:
- Horizontal Scaling โ Add more full nodes behind the load balancer.
- Read Replicas โ Use dedicated nodes for read-only queries to reduce load on write-capable nodes.
- Caching โ Cache frequently accessed data (e.g., account balances) at the API gateway.
- Connection Pooling โ Reuse gRPC connections to reduce overhead.
- Geo-distribution โ Deploy nodes in multiple regions to reduce latency for global users.
Monitor RPC latency, error rates, and request volume. Use tools like Prometheus, Grafana, or Datadog to visualize metrics and set up alerts.