Logo
新用户订阅 RPC,首月享 6.5 折优惠查看优惠
RPC Assistant

TON API: How to Choose and Use Endpoints for Mainnet and Testnet

摘要

TON API services provide HTTP and WebSocket access to the TON blockchain. Developers can choose between public endpoints, hosted APIs like TON Center and TonAPI, or dedicated node infrastructure from providers like OnFinality. This article compares available options, lists endpoint settings, and covers common setup and debugging steps.

TON API Decision Checklist

Before integrating a TON API, evaluate these criteria to match your workload:

CriterionWhat to checkWhy it matters
Read vs. write operationsDoes the provider support sending transactions, or only reads?Writing requires liteserver access or wallet integration.
Rate limitsFree tier vs. paid plan limits (requests per second).High-traffic dApps need higher limits or dedicated nodes.
Historical data depthDoes the API provide indexed history (traces, jettons, NFTs)?Indexed APIs like TON Center v3 enable rich queries without running a full node.
Proof verificationResponses include Merkle proofs for trustless verification.Liteserver-based APIs return proofs; REST APIs typically do not.
WebSocket / streamingReal-time event subscriptions (blocks, transactions).Needed for live dashboards, wallets, and notification systems.
Self-hosted optionCan you run your own API instance?For full control, deploy ton-http-api or use dedicated nodes.
Testnet supportAre testnet endpoints and faucets available?Essential for development and QA before mainnet deployment.
Pricing modelPay-as-you-go vs. monthly subscription vs. dedicated node.Variable costs scale with volume; dedicated nodes offer predictable pricing.

What Is a TON API?

TON (The Open Network) uses a custom binary protocol (ADNL) for node communication. A TON API acts as a bridge, translating standard HTTP/HTTPS requests into ADNL calls to liteservers. This allows developers to query blockchain data, send transactions, and subscribe to events using familiar REST or GraphQL interfaces.

Most TON APIs are built on top of the open-source ton-http-api project, which can also be self-hosted. The main differences between providers lie in indexing, rate limits, reliability, and added services like webhooks or SDKs.

TON API Providers: Main Options

1. TON Center

TON Center offers two API versions:

  • v2: Direct liteserver proxy – supports proofs, but no indexing. Good for simple reads and writes.
  • v3: Indexed database – enables rich queries for jettons, NFTs, traces, and historical data. No proof responses.

Both versions are free with an API key (up to a certain rate) and can be self-hosted. Testnet endpoints are available.

2. TonAPI (tonapi.io)

TonAPI is a SaaS platform providing REST, GraphQL, and streaming APIs. It features an integrated indexer, webhooks, and SDKs. Pricing is based on request volume, with a free tier for low usage. It does not return cryptographic proofs.

3. OnFinality TON API

OnFinality provides TON RPC endpoints as part of its multi-chain API service. You can access public endpoints or provision a dedicated node for higher reliability and rate limits. OnFinality also supports testnet and offers failover across multiple node instances. Check the pricing page for plan details.

4. Self-Hosted

Deploy the ton-http-api project on your own infrastructure. Recommended hardware: 1 vCPU, 2 GB RAM (without cache) or 2 vCPU, 4 GB RAM (with cache). You must also run a TON liteserver or connect to public liteservers.

TON API Endpoints: Mainnet and Testnet Settings

Below are common endpoints. Always verify the latest URLs in the official documentation.

ProviderMainnet EndpointTestnet EndpointNotes
TON Center (v2)https://toncenter.com/api/v2/https://testnet.toncenter.com/api/v2/Requires API key.
TON Center (v3)https://toncenter.com/api/v3/https://testnet.toncenter.com/api/v3/Indexed queries.
TonAPIhttps://tonapi.io/Not publicly documentedUse TonAPI console.
OnFinalitySee TON network pageSee TON testnet pageAPI key or IP whitelist.

Chain ID (workchain): 0 for basechain, -1 for masterchain.

Getting Started: Faucet and First Request

Testnet Faucet

Use the TON testnet faucet to receive free test coins. Common faucets:

Example: Retrieve Account Balance via TON Center v2

curl -X GET "https://toncenter.com/api/v2/getAddressBalance?address=EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N&api_key=YOUR_API_KEY"

If successful, response:

{"ok":true,"result":"5000000000"}

Using OnFinality TON API

After obtaining an API key from OnFinality, you can make requests to the provided endpoint. For example:

curl -X POST "https://ton-mainnet.onfinality.io/api/v2/" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{"method":"getAddressBalance","params":{"address":"EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N"}}'

Common Pitfalls and Debugging

  • Rate limiting: Public endpoints (no key) are heavily rate-limited. Always register for an API key. For production, consider dedicated infrastructure.
  • Missing proofs: If your use case requires trustless verification, use a liteserver-based API (TON Center v2, self-hosted ton-http-api). Indexed APIs (v3, TonAPI) do not return proofs.
  • Workchain confusion: Most user addresses are in workchain 0. Masterchain addresses start with -1: and require special handling.
  • Transaction submission: To send transactions, you must serialize the message externally and pass it as a base64 or hex string. Most APIs provide a /sendBoc endpoint for this.
  • CORS issues: If calling from a browser, ensure the API supports CORS or use a backend proxy.

Key Takeaways

  • TON APIs abstract the low-level ADNL protocol, offering HTTP/JSON access.
  • Choose between direct liteserver proxies (proofs, no indexing) and indexed APIs (rich queries, no proofs).
  • For production workloads, evaluate rate limits, historical depth, and failover support. Dedicated nodes or multi-provider setups improve reliability.
  • Testnet endpoints and faucets are essential for development. Always verify compatibility with your tools (e.g., wallet SDKs).
  • OnFinality provides TON RPC endpoints and dedicated nodes with flexible pricing and global coverage.

Frequently Asked Questions

Q: What is the difference between TON Center v2 and v3? A: v2 is a direct liteserver proxy that returns Merkle proofs; v3 uses an indexed database for richer queries but does not return proofs. Choose v2 if you need verifiable responses, v3 for complex data retrieval.

Q: Can I use a TON API without an API key? A: Yes, but rate limits are very low (e.g., 1 request/second). Register for a free key to increase limits.

Q: How do I send a transaction via TON API? A: Use the sendBoc endpoint with a serialized message in base64 or hex. Example: POST /api/v2/sendBoc with body {"boc":"te6cck..."}.

Q: Does OnFinality support TON testnet? A: Yes, OnFinality provides TON testnet endpoints. See the network page for details.

Q: What is the TON mainnet chain ID? A: The workchain ID is typically 0 for basechain, -1 for masterchain. There is no separate chain ID like EVM chains; the network is identified by the global config.

RPC 知识库

相关 RPC 内容

RPC 提供商选择Sui

专用 Sui gRPC 节点:流式传输、容量与隔离

专用 Sui gRPC 节点为您的团队提供隔离的全节点环境,用于高吞吐的 Sui 数据访问。您不必共享限速的公共或多租户端点,而是运行一个为索引器、后端服务和订阅消费者量身定制的节点。gRPC API 使用基于 HTTP/2 的 Protocol Buffers,使检查点、交易和事件流的效率高于轮询...

网络 RPCOptimism

Optimism API:它是什么以及如何在 OP Mainnet 上使用

Optimism API 是一组 JSON-RPC 端点,允许应用程序在 OP Mainnet(一个基于乐观汇总构建的以太坊 Layer 2)上读写数据。它遵循与以太坊相同的 JSON-RPC 标准,因此您可以使用熟悉的库(如 ethers 或 viem)与链进行交互。本文解释了什么是 Optimi...

网络 RPCSonic

选择 Sonic RPC 提供商时应该关注什么?

# 选择 Sonic RPC 提供商时应该关注什么? Sonic RPC 提供商之所以重要,是因为 Web3 应用依赖稳定的端点访问来进行读取、交易、仪表盘和后端工作流。正确的配置应匹配你的工作负载,支持你所需的网络和测试网,使限制可见,并在共享 RPC 不再足够时提供扩展路径。 对于 Sonic ...

网络 RPCBNB Chain

如何在BNB智能链上质押:分步指南

本指南介绍如何在BNB智能链(BSC)上质押BNB,涵盖委托给验证人和流动性质押两种方式。包括连接钱包、选择验证人、监控质押的实际步骤,以及关于质押交易RPC可靠性的指导。...

网络 RPCEfinity

Solana RPC 节点:它是什么、如何连接以及如何选择

Solana RPC 节点是暴露 Solana JSON-RPC API 的服务器,允许应用程序读取链上数据并提交交易。本文解释了 Solana RPC 节点的工作原理、如何连接到公共和专用端点,以及为生产应用选择基础设施时应评估的内容。...

网络 RPCSolana

什么是 Solana 的 RPC?如何选择合适的端点?

Solana RPC 端点让您的 dApp 读取链上状态、提交交易并订阅实时更新。本指南解释 Solana RPC 如何工作、如何连接公共和专用端点,以及在生产环境选择基础设施时应评估哪些因素。...

永远不用担心基础设施

OnFinality 消除了 DevOps 的繁重工作,让您能够更聪明、更快地构建。

开始