TON Gateway
Unthrottled anonymous RPC access to TON blockchain via the dozens of decentralized nodes of the Orbs Network.
Access a network of public API endpoints that allow TON dapp clients to make HTTP queries from the browser to TON blockchain (call getters, balances, get block data, etc). Access is unrestricted without an API Key and without requiring dapps to run any backend.
Supports all popular RPC protocols:
Getting Started
npm install @orbs-network/ton-gateway
Using toncenter-api-v2 Node.js:
import { TonClient, Address } from "ton";
import { getTonCenterV2Endpoint } from "@orbs-network/ton-gateway";
const endpoint = await getTonCenterV2Endpoint();
const client = new TonClient({ endpoint });
const address = Address.parseFriendly("EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N").address;
const balance = await client.getBalance(address);
With TonWeb library:
import TonWeb from "tonweb";
import { getTonCenterV2Endpoint } from "@orbs-network/ton-gateway";
const endpoint = await getTonCenterV2Endpoint();
const tonweb = new TonWeb(new TonWeb.HttpProvider(endpoint));
const balance = await tonweb.getBalance("EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N");
Using ton-api-v4 Node.js:
import { TonClient4 } from "ton";
import { getTonApiV4Endpoint } from "@orbs-network/ton-gateway";
const endpoint = await getTonApiV4Endpoint();
const client4 = new TonClient4({ endpoint });
let latest = await client4.getLastBlock();
console.log('latest seqno is:',latest.last.seqno);
Using browser script:
<script src="https://cdn.jsdelivr.net/gh/orbs-network/ton-gateway@1.4.0/dist/index.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/toncenter/tonweb/dist/tonweb.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function () {
TonGateway.getHttpEndpoint().then((endpoint) => {
const tonweb = new TonWeb(new TonWeb.HttpProvider(endpoint));
tonweb.getBalance("EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N").then((balance) => {
console.log(balance);
});
});
});
</script>
Parameters
toncenter-V2
export async function getTonCenterV2Endpoint(network?: Network, suffix?: string): Promise<string>
-
network
- override which TON network do you want to use:
mainnet
- TON mainnet (default)
testnet
- (supported only in toncenter-api-v2) the first TON testnet
-
suffix
- endpoints trailing path suffix, default is jsonRPC
ton-api-V4
export async function getTonApiV4Endpoint(suffix?: string): Promise<string>
suffix
- endpoints trailing path suffix, default is empty string
const endpoint = await getTonApiV4Endpoint('/block/latest');
const last = await fetch(endpoint);
const json = await last.json();
console.log('last seqno is:', json.last.seqno);
Cache & Rate limits:
- The gateway is using Fastlycache control
- request results has 2 seconds TTL
- there is a rate limit of 10rps over 1 minute
Benefits of using the Orbs TON Gateway
-
No throttling for anonymous users
RPC gateways like https://toncenter.com/api/v2/jsonRPC throttle anonymous users to 1 request per second. Most dapps cannot operate under these restrictions since their users are anonymous. The Orbs Network endpoints are designed to serve anonymous dapp users and will not restrict your users from using your dapp client, except the generous rate limit mentioned above.
-
No need for registering an API Key
RPC gateways like https://toncenter.com/api/v2/jsonRPC reduce user throttling by requiring you to register an API Key. This API Key cannot be stored client-side since it can be abused (it's supposed to be a secret) and dapps should not run a centralized backend to store this secret since they should be decentralized.
-
No need to run your own RPC backend
If you're building a dapp, your dapp should be decentralized so it can be trustless. If you're running your own centralized backend as part of your dapp, you've made your dapp centralized. If your backend suffers downtime for example, your users will lose access to their funds. If the infrastructure is decentralized, you don't need to worry about it.
-
Decentralized access to the chain
By relying on https://toncenter.com/api/v2/jsonRPC, you're relying on a centralized business (toncenter.com), not a protocol. The Orbs Network TON Gateway is a decentralized protocol operated by dozens of independent nodes that are all part of the Orbs Network. The network mainnet is running since 2019 and validators are staked with Proof-of-Stake consensus with over $100 million TVL locked. The network is extremely robust against downtime due to the number of independent nodes.