What is TON RPC and how do you use it?
Key Takeaways
- TON RPC bridges standard HTTP/JSON-RPC to TON's native ADNL protocol.
- The TON Center API v2 is the most widely used RPC interface for TON.
- Public endpoints exist but are rate-limited; production apps need a dedicated provider.
- TON testnet RPC is essential for development and testing without mainnet costs.
- Reliable TON RPC providers offer geo-distributed endpoints for low latency.
- OnFinality provides TON mainnet and testnet RPC endpoints with dedicated node options.
- Always monitor RPC performance and have fallback endpoints for high availability.
Understanding TON RPC and Its Role
TON (The Open Network) is a blockchain with a unique multi-threaded, sharded architecture. Unlike Ethereum, TON nodes communicate using the ADNL (Abstract Datagram Network Layer) protocol, which is not directly accessible from web applications. TON RPC acts as a bridge, exposing a standard JSON-RPC or REST API that developers can use to query blockchain data, send transactions, and interact with smart contracts.
The most common TON RPC implementation is the TON Center API v2, which provides endpoints for accounts, blocks, transactions, and messages. It also supports WebSocket for real-time streaming. Understanding this interface is the first step to building on TON.
- TON RPC translates HTTP requests to ADNL for node communication.
- TON Center API v2 is the de facto standard for TON RPC.
- Supports both REST and JSON-RPC styles.
- WebSocket endpoints available for real-time data.
TON RPC Endpoints: Mainnet and Testnet
To interact with TON, you need an RPC endpoint URL. The TON Foundation provides public endpoints, but these are rate-limited and not suitable for production. For development, you can use the testnet endpoints to experiment without risking real assets.
Below is a comparison of the default public endpoints and what to expect from managed providers.
| Criterion | What to check | Why it matters |
|---|---|---|
| Network | Mainnet vs Testnet | Testnet is free but has limited data; mainnet is for live apps. |
| Rate Limits | Requests per second (RPS) | Public endpoints often throttle at 1 RPS; production needs higher limits. |
| Geo-Distribution | Server locations | Global distribution reduces latency for users worldwide. |
| Archive Data | Historical state access | Archive nodes allow querying past states, useful for analytics. |
How to Choose a TON RPC Provider
When selecting a TON RPC provider for your dApp, consider factors like uptime, latency, request limits, and pricing. Public endpoints are fine for prototyping, but production applications require reliable infrastructure. Look for providers that offer geo-balanced endpoints, dedicated node options, and support for both mainnet and testnet.
OnFinality offers TON RPC endpoints with a free tier and scalable dedicated nodes. You can start with the shared endpoint and upgrade as your project grows. Always test provider performance from your target user locations.
- Check uptime guarantees and historical performance.
- Evaluate latency from multiple global regions.
- Compare pricing models: pay-as-you-go vs monthly plans.
- Ensure support for both mainnet and testnet.
- Consider dedicated nodes for high-throughput or latency-sensitive apps.
Connecting to TON RPC: Code Examples
Connecting to TON RPC is straightforward. Here's how to make a basic request using the TON Center API v2. Replace the endpoint URL with your provider's URL.
- Example: Get account information using curl: curl https://toncenter.com/api/v2/getAddressInformation?address=EQD...
- For JavaScript, use fetch or axios to call the REST endpoints.
- For real-time data, use WebSocket to wss://toncenter.com/api/v2/stream.
Common Pitfalls and Troubleshooting
Developers new to TON often face issues like rate limiting, incorrect endpoint URLs, or misunderstanding the asynchronous nature of TON transactions. Unlike EVM chains, TON does not have a mempool; transactions are processed in shards. Ensure you are using the correct API version and that your provider supports the methods you need.
If you encounter errors, check your API key (if required), verify the network (mainnet vs testnet), and review the TON Center API documentation for method parameters.
- Rate limiting: Use a provider with higher RPS limits or dedicated nodes.
- Transaction delays: TON uses asynchronous sharding; monitor status via getTransactions.
- Incorrect endpoint: Double-check the URL and network selection.
- Missing methods: Some providers may not support all TON Center API methods.
Why Use a Managed TON RPC Provider?
Running your own TON node requires significant infrastructure and maintenance. Managed providers handle node synchronization, uptime, and scaling, allowing you to focus on development. OnFinality provides TON RPC as a service with automatic failover and global load balancing.
For projects with high transaction volumes or strict latency requirements, dedicated TON nodes offer isolated resources and guaranteed performance. Evaluate your needs and choose the right tier.
- No node management overhead.
- Automatic updates and security patches.
- Scalable from free tier to dedicated clusters.
- 24/7 monitoring and support.
Frequently Asked Questions
What is TON RPC?
TON RPC is a service that allows web applications to interact with the TON blockchain using standard HTTP/JSON-RPC or REST APIs. It translates requests into TON's native ADNL protocol.
How do I get a TON RPC endpoint?
You can use public endpoints from TON Center, but for production, use a managed provider like OnFinality. Sign up, select TON network, and get your endpoint URL.
Is TON RPC free?
Public endpoints are free but rate-limited. Managed providers offer free tiers with limited requests and paid plans for higher usage.
What is the difference between TON mainnet and testnet RPC?
Mainnet RPC connects to the live TON blockchain with real assets. Testnet RPC connects to a separate test network for development and testing without financial risk.
Can I use TON RPC with MetaMask?
No, MetaMask only supports EVM-compatible chains. TON is non-EVM, so you need a TON-specific wallet like Tonkeeper or a custom integration.