Skip to content
This repository was archived by the owner on Sep 3, 2026. It is now read-only.

Commit b2686a6

Browse files
authored
Merge pull request #478 from ton-org/feat/TON-1658-minter-tonapi
TON-1658: tonapi support in minter
2 parents 2f79847 + 156bbef commit b2686a6

2 files changed

Lines changed: 36 additions & 11 deletions

File tree

‎apps/appkit-minter/src/core/configs/app-kit.ts‎

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
ApiClientTonApi,
1414
ApiClientToncenter,
1515
createTonCenterStreamingProvider,
16+
createTonApiStreamingProvider,
1617
} from '@ton/appkit';
1718
import { createDeDustProvider } from '@ton/appkit/swap/dedust';
1819
import { createOmnistonProvider } from '@ton/appkit/swap/omniston';
@@ -22,27 +23,49 @@ import { createDecentProvider } from '@ton/appkit/crypto-onramp/decent';
2223
import { createTonApiGaslessProvider } from '@ton/appkit/gasless/tonapi';
2324

2425
import {
26+
ENV_TON_API_PROVIDER,
2527
ENV_TON_API_KEY_TESTNET,
2628
ENV_TON_API_KEY_MAINNET,
29+
ENV_TON_API_KEY_TETRA,
2730
ENV_DECENT_API_KEY,
2831
ENV_TONCONNECT_MANIFEST_URL,
2932
} from '@/core/configs/env';
3033

31-
const mainnetApiClient = new ApiClientToncenter({
32-
network: Network.mainnet(),
33-
apiKey: ENV_TON_API_KEY_MAINNET,
34-
});
34+
const useTonApi = ENV_TON_API_PROVIDER === 'tonapi';
3535

36-
const testnetApiClient = new ApiClientToncenter({
37-
network: Network.testnet(),
38-
apiKey: ENV_TON_API_KEY_TESTNET,
39-
});
36+
// Switch the underlying API client between Toncenter and TonAPI based on the
37+
// configured provider. When 'tonapi' is selected the keys below are treated as
38+
// TonAPI keys; otherwise they are Toncenter keys.
39+
const createApiClient = (network: Network, apiKey?: string) =>
40+
useTonApi ? new ApiClientTonApi({ network, apiKey }) : new ApiClientToncenter({ network, apiKey });
41+
42+
const mainnetApiClient = createApiClient(Network.mainnet(), ENV_TON_API_KEY_MAINNET);
4043

44+
const testnetApiClient = createApiClient(Network.testnet(), ENV_TON_API_KEY_TESTNET);
45+
46+
// Tetra is a TonAPI-only network, so it always uses the TonAPI client.
4147
const tetraApiClient = new ApiClientTonApi({
4248
network: Network.tetra(),
4349
endpoint: 'https://tetra.tonapi.io',
50+
apiKey: ENV_TON_API_KEY_TETRA,
4451
});
4552

53+
// Match the streaming provider to the configured API provider.
54+
const createStreamingProvider = useTonApi ? createTonApiStreamingProvider : createTonCenterStreamingProvider;
55+
56+
// Pass the keys to the gasless relayer only when TonAPI is the configured
57+
// provider — otherwise they are Toncenter keys and don't apply. Without a key
58+
// it falls back to the public TonAPI endpoints.
59+
const gaslessConfig =
60+
useTonApi && (ENV_TON_API_KEY_MAINNET || ENV_TON_API_KEY_TESTNET)
61+
? {
62+
chains: {
63+
[Network.mainnet().chainId]: { apiKey: ENV_TON_API_KEY_MAINNET },
64+
[Network.testnet().chainId]: { apiKey: ENV_TON_API_KEY_TESTNET },
65+
},
66+
}
67+
: undefined;
68+
4669
export const appKit = new AppKit({
4770
networks: {
4871
[Network.mainnet().chainId]: { apiClient: mainnetApiClient },
@@ -62,8 +85,8 @@ export const appKit = new AppKit({
6285
createTonstakersProvider(),
6386
createLayerswapProvider(),
6487
createDecentProvider({ apiKey: ENV_DECENT_API_KEY }),
65-
createTonCenterStreamingProvider({ network: Network.mainnet(), apiKey: ENV_TON_API_KEY_MAINNET }),
66-
createTonCenterStreamingProvider({ network: Network.testnet(), apiKey: ENV_TON_API_KEY_TESTNET }),
67-
createTonApiGaslessProvider(),
88+
createStreamingProvider({ network: Network.mainnet(), apiKey: ENV_TON_API_KEY_MAINNET }),
89+
createStreamingProvider({ network: Network.testnet(), apiKey: ENV_TON_API_KEY_TESTNET }),
90+
createTonApiGaslessProvider(gaslessConfig),
6891
],
6992
});

‎apps/appkit-minter/src/core/configs/env.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
*
77
*/
88

9+
export const ENV_TON_API_PROVIDER = import.meta.env?.VITE_TON_API_PROVIDER === 'tonapi' ? 'tonapi' : 'toncenter';
910
export const ENV_TON_API_KEY_MAINNET =
1011
import.meta.env.VITE_TON_API_KEY ?? '25a9b2326a34b39a5fa4b264fb78fb4709e1bd576fc5e6b176639f5b71e94b0d';
1112
export const ENV_TON_API_KEY_TESTNET =
1213
import.meta.env.VITE_TON_API_TESTNET_KEY ?? 'd852b54d062f631565761042cccea87fa6337c41eb19b075e6c7fb88898a3992';
14+
export const ENV_TON_API_KEY_TETRA = import.meta.env.VITE_TON_API_TETRA_KEY ?? '';
1315
export const ENV_DECENT_API_KEY = import.meta.env.VITE_DECENT_API_KEY ?? '5c951bc81da566bbd030ba8e20724063';
1416

1517
const DEV_TONCONNECT_MANIFEST_URL = 'https://tonconnect-sdk-demo-dapp.vercel.app/tonconnect-manifest.json';

0 commit comments

Comments
 (0)