Using free high TONAPI limits in your dApp with Tonkeeper
Overview
TONAPI is already available for free, but with a default rate limit of 1 request per second (1 RPS). If your dApp requires higher limits, you can take advantage of Tonkeeper's built-in mechanism to gain additional API capacity at no extra cost.
Tonkeeper (opens in a new tab) introduces a way for dApps to access high TONAPI limits for free. This feature allows dApps running in the Tonkeeper browser or in any browser with the Tonkeeper extension installed to leverage a built-in proxy mechanism that optimizes API requests.
How It Works
When a dApp is opened inside the Tonkeeper browser or a browser with the Tonkeeper extension, the global window.tonapi
object becomes available. If the dApp is using @ton-api/client (opens in a new tab), it will automatically leverage this object. window.tonapi
provides a custom fetch
implementation that routes requests through Tonkeeper's internal proxy, sending them on behalf of Tonkeeper's TONAPI provider.
Key Benefits
- Higher rate limits: Requests made via
window.tonapi.fetch
are processed with higher TONAPI limits. - No extra setup: The dApp does not need to modify API calls—just use
@ton-api/client
as usual. - Works in the Tonkeeper browser and in any browser with the Tonkeeper extension installed.
Integration Guide
1. Ensuring Proper API Key Usage
Even when using window.tonapi.fetch
, you must provide a valid TONAPI key when initializing @ton-api/client
. The key can be a free-tier key, but it must be valid.
import { TonApiClient } from "@ton-api/client";
const tonApi = new TonApiClient({
apiKey: "your-valid-tonapi-key"
});
If window.tonapi
is available, @ton-api/client
will automatically use window.tonapi.fetch
for making requests.
2. Restricting Your dApp to free high limit
If you want to ensure that your dApp only functions in environments where window.tonapi
is available , you can enforce this restriction:
if (!window.tonapi) {
alert("This dApp requires Tonkeeper to function properly.");
throw new Error("window.tonapi is required");
}
Summary
window.tonapi.fetch
allows dApps running in the Tonkeeper browser or a browser with the Tonkeeper extension to use high TONAPI limits.- You must provide a valid TONAPI key when initializing
@ton-api/client
. - You can restrict your dApp to work only when
window.tonapi
is available if you need high RPS.
For more details about methods, go to REST API section.