İçeriğe geç

TypeScript SDK

Bu içerik henüz dilinizde mevcut değil.

@takowtf/sdk reads the pool through any @ton/core provider and returns messages ready to send. It has one peer dependency, @ton/core.

Terminal window
npm install @takowtf/sdk @ton/core
import { TonClient } from '@ton/ton';
import { toNano } from '@ton/core';
import { Tako, toTonConnect } from '@takowtf/sdk';
const tako = new Tako({ client: new TonClient({ endpoint }), network: 'testnet' });
const message = await tako.stake({ amount: toNano('10') });
await tonConnectUI.sendTransaction(toTonConnect([message]));

client is anything with a provider(address) method: TonClient, TonClient4, or a sandbox Blockchain in tests.

const pool = await tako.pool();
// pool.rate, pool.totalCoins, pool.instantLiquidity, pool.apr (percent, null while empty)
const me = await tako.position(owner);
// me.shares (takoGRAM), me.value (Gram), me.wallet (share wallet address)
const quote = await tako.quoteUnstake(me.shares);
// quote.instant, quote.fee, quote.payout
Call Returns
pool() pool state with APR
fees() the fee of every action
position(owner) takoGRAM wallet, shares and their Gram value
quoteUnstake(shares) instant or queued, fee and payout
stake({ amount, recipient?, referrer? }) deposit message
unstake({ owner, shares, mode? }) burn message; mode is Auto, InstantOnly or QueueOnly
claimAddress(index), claim(address) a claim’s address and state, null if not deployed
redeem(claim) redeem message
draws(owner, vault?) prize, jackpot, players, next draw and the owner’s deposit
enterDraws({ owner, shares, vault? }), leaveDraws({ amount, vault? }) draw messages
groupVault(chatId) the prize vault of a Telegram chat
explainError(code) what an exit code means
toTonConnect(messages) the request for sendTransaction

The message builders also work offline: stake, unstake, redeem, enterDraws, leaveDraws and shareWallet take addresses and fees directly. Use them when you already have the fees, for example in a backend that batches transactions.

The SDK’s own tests deploy the whole protocol into @ton/sandbox and run every call against real contracts. Your tests can do the same with the protocol package’s deploy helper, with no network.