TypeScript SDK
Цей контент ще не доступний вашою мовою.
The official TypeScript SDK wraps the Tegro Finance DEX so you can read market data, quote swaps and liquidity, and build ready-to-sign transactions — in a few lines, with full types.
- npm:
@tegroton/tegro-finance - Source: github.com/TegroTON/tegro-finance-sdk
- License: MIT · Runtime deps:
@ton/coreonly
npm install @tegroton/tegro-financeNode.js ≥ 18 (uses global fetch). Works in the browser too. TON Connect is an optional peer dependency, needed only where you actually sign.
Two integration modes
Section titled “Two integration modes”- API mode — a thin, typed HTTP client over
https://api.tegro.finance. Read pools/assets, quote, and let the backend prepare transactions. - On-chain mode — build swap & liquidity transactions entirely client-side with
TegroFinanceRouter, with no dependency on our backend. Message bodies are verified byte-for-byte against the production contracts.
Both are non-custodial: the user’s wallet signs every state change via TON Connect. The SDK never holds, sees, or transmits a private key.
Read & quote
Section titled “Read & quote”import { TegroFinanceClient, toUnits, fromUnits, TON_NATIVE_ADDRESS } from "@tegroton/tegro-finance";
const client = new TegroFinanceClient();const assets = await client.getAssets();const tgr = Object.values(assets).find((a) => a.symbol === "TGR")!;
const quote = await client.simulateSwap({ offerAddress: TON_NATIVE_ADDRESS, askAddress: tgr.contract_address, units: toUnits("1", 9), // 1 TON slippageTolerance: 0.01, // 1%});
console.log(`1 TON → ~${fromUnits(quote.ask_units, tgr.decimals)} TGR`);Build a swap and let the wallet sign it
Section titled “Build a swap and let the wallet sign it”import { TegroFinanceClient, toUnits, applySlippage, toTonConnectMessages, TON_NATIVE_ADDRESS,} from "@tegroton/tegro-finance";import { useTonConnectUI, useTonAddress } from "@tonconnect/ui-react";
const client = new TegroFinanceClient();const [tonConnectUI] = useTonConnectUI();const userAddress = useTonAddress();
const offerUnits = toUnits("1", 9);const quote = await client.simulateSwap({ offerAddress: TON_NATIVE_ADDRESS, askAddress: tgrAddress, units: offerUnits, slippageTolerance: 0.01,});
const tx = await client.buildSwap({ userWalletAddress: userAddress, offerJettonAddress: TON_NATIVE_ADDRESS, offerAmount: offerUnits, askJettonAddress: tgrAddress, minAskAmount: applySlippage(quote.ask_units, 0.01),});
await tonConnectUI.sendTransaction(toTonConnectMessages(tx));On-chain mode (no backend)
Section titled “On-chain mode (no backend)”import { TegroFinanceRouter, tonApiResolver, cachingResolver } from "@tegroton/tegro-finance";
const router = new TegroFinanceRouter({ routerAddress: "…", // read from /api/v1/pools proxyTonAddress: "…", // the router's pTON wallet master resolver: cachingResolver(tonApiResolver()),});
const tx = await router.getSwapTxParams({ /* same params as buildSwap */ });await tonConnectUI.sendTransaction(tx); // already TON Connect-shapedgetProvideLiquidityTxParams, getCreatePoolTxParams, getRemoveLiquidityTxParams and getUnlockPoolTxParams work the same way.
Helpers
Section titled “Helpers”toUnits/fromUnits— BigInt-exact conversion between human amounts and smallest units.applySlippage(expected, tolerance)— floor the minimum you’ll accept.toTonConnectMessages(tx)— adapt an API-built transaction tosendTransaction().