### Run Development Server Source: https://github.com/ston-fi/sdk/blob/main/examples/next-js-app/README.md Starts the development server using the turbo command. ```sh turbo dev ``` -------------------------------- ### Install STON.fi Stake SDK with NPM Source: https://github.com/ston-fi/sdk/blob/main/packages/stake-sdk/README.md Install the STON.fi Stake SDK package using NPM. Ensure you have the @ton/ton package installed first. ```bash npm install @ston-fi/stake-sdk ``` -------------------------------- ### Install Dependencies Source: https://github.com/ston-fi/sdk/blob/main/examples/next-js-app/README.md Installs the necessary project dependencies using pnpm. ```sh pnpm install ``` -------------------------------- ### Install STON.fi Stake SDK with PNPM Source: https://github.com/ston-fi/sdk/blob/main/packages/stake-sdk/README.md Install the STON.fi Stake SDK package using PNPM. Ensure you have the @ton/ton package installed first. ```bash pnpm install @ston-fi/stake-sdk ``` -------------------------------- ### Install STON.fi Stake SDK with Yarn Source: https://github.com/ston-fi/sdk/blob/main/packages/stake-sdk/README.md Install the STON.fi Stake SDK package using Yarn. Ensure you have the @ton/ton package installed first. ```bash yarn add @ston-fi/stake-sdk ``` -------------------------------- ### Initialize PtonV2_1 with Custom Gas Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/configuration.md Example of creating a PtonV2_1 instance with customized gas amounts for TON transfers and wallet deployment. ```typescript import { DEX } from "@ston-fi/sdk"; import { toNano } from "@ton/ton"; const ptonV2_1 = DEX.v2_2.pTON.create(ptonAddress, { gasConstants: { tonTransfer: toNano("0.02"), deployWallet: toNano("0.15") } }); ``` -------------------------------- ### Install STON.fi SDK with PNPM Source: https://github.com/ston-fi/sdk/blob/main/packages/sdk/README.md Use this command to add the STON.fi SDK package to your project when using PNPM. ```bash pnpm install @ston-fi/sdk ``` -------------------------------- ### Install STON.fi SDK with NPM Source: https://github.com/ston-fi/sdk/blob/main/packages/sdk/README.md Use this command to add the STON.fi SDK package to your project when using NPM. ```bash npm install @ston-fi/sdk ``` -------------------------------- ### Example: Deploying a pTON Wallet Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/pton.md Illustrates how to obtain the transaction parameters for deploying a pTON wallet, specifying the owner and excess addresses, and optionally the gas amount for deployment. ```typescript const deployTxParams = await ptonV2_1.getDeployWalletTxParams(provider, { ownerAddress: userAddress, excessAddress: userAddress, gasAmount: "100000000" // 0.1 TON }); await sender.send(deployTxParams); ``` -------------------------------- ### Initialize STON.fi Client Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/configuration.md Example of creating a new STON.fi Client instance with specified endpoint, API key, and a custom STON.fi API client. ```typescript import { Client } from "@ston-fi/sdk"; const client = new Client({ endpoint: "https://toncenter.com/api/v2/jsonRPC", key: "YOUR_API_KEY", stonApiClient: new StonApiClient() }); ``` -------------------------------- ### Example: Staking Tokens with StakeNftMinter Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/stake-nft.md Demonstrates how to use the `getStakeTxParams` method to prepare and send a transaction for staking tokens. Ensure you have the necessary SDK imports and provider/sender configurations. ```typescript import { StakeNftMinter } from "@ston-fi/stake-sdk"; import { toNano } from "@ton/ton"; const minter = StakeNftMinter.create("EQA..."); const thirtyDays = 30 * 24 * 60 * 60; // seconds const txParams = await minter.getStakeTxParams(provider, { userWalletAddress: userAddress, jettonAddress: tokenAddress, jettonAmount: "1000000000", // 1 token (9 decimals) durationSeconds: thirtyDays, nftRecipient: userAddress, tokenRecipient: userAddress }); await sender.send(txParams); ``` -------------------------------- ### Install STON.fi SDK with Yarn Source: https://github.com/ston-fi/sdk/blob/main/packages/sdk/README.md Use this command to add the STON.fi SDK package to your project when using Yarn. ```bash yarn add @ston-fi/sdk ``` -------------------------------- ### Initialize StakeNftMinter with Custom Gas Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/configuration.md Example of creating a StakeNftMinter instance with customized gas amounts for staking and forward transactions. ```typescript import { StakeNftMinter } from "@ston-fi/stake-sdk"; import { toNano } from "@ton/ton"; const minter = StakeNftMinter.create(minerAddress, { gasConstants: { stake: toNano("0.5"), stakeForward: toNano("0.4") } }); ``` -------------------------------- ### Stake Tokens using StakeNftMinter Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/README.md Example of how to get transaction parameters for staking tokens using the StakeNftMinter from the stake-sdk. Specify the token address, amount, and desired staking duration. ```typescript import { StakeNftMinter } from "@ston-fi/stake-sdk"; const minter = StakeNftMinter.create(minerAddress); const txParams = await minter.getStakeTxParams(provider, { userWalletAddress: userAddress, jettonAddress: tokenAddress, jettonAmount: "1000000000", durationSeconds: 30 * 24 * 60 * 60 // 30 days }); await sender.send(txParams); ``` -------------------------------- ### Example of AddressType Usage Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/types.md Demonstrates how AddressType can accept both string and Address object formats for contract initialization. This flexibility simplifies address handling. ```typescript import { JettonMinter } from "@ston-fi/sdk"; import { Address } from "@ton/ton"; // Both forms are accepted const minter1 = JettonMinter.create("EQA..."); const minter2 = JettonMinter.create(Address.parse("EQA...")); ``` -------------------------------- ### Farm SDK Usage Example Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/farm.md This snippet shows how to deposit LP tokens, claim rewards, and unstake assets using the FARM SDK. Ensure you have the necessary provider and sender objects initialized. ```typescript import { FARM } from "@ston-fi/sdk"; const farmMinter = FARM.v3.FarmNftMinter.create("EQA..."); const farmItem = FARM.v3.FarmNftItem.create("EQB..."); // Deposit LP tokens const depositTxParams = await farmMinter.getDepositNftTxParams(provider, { userWalletAddress: userAddress, lpTokenAddress: lpTokenAddress, lpTokenAmount: "1000000000" // 1 token }); await sender.send(depositTxParams); // Later: claim rewards const claimTxParams = await farmItem.getClaimRewardsTxParams(provider); await sender.send(claimTxParams); // Unstake const unstakeTxParams = await farmItem.getUnstakeTxParams(provider); await sender.send(unstakeTxParams); ``` -------------------------------- ### Customizing Router Gas Constants and Deadline Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/configuration.md Example of creating a DEX router instance with customized gas constants for swap operations and an extended transaction deadline. ```typescript import { DEX } from "@ston-fi/sdk"; import { toNano } from "@ton/ton"; const router = DEX.v2_2.Router.CPI.create(routerAddress, { gasConstants: { swapJettonToJetton: { gasAmount: toNano("0.4"), // Increase base gas forwardGasAmount: toNano("0.3") // Increase forward gas } }, txDeadline: 1800000 // 30 minutes }); ``` -------------------------------- ### Example of Query ID Usage Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/types.md Shows how to specify a queryId when calling a method like getStakeTxParams to correlate transaction requests with responses. ```typescript const txParams = await minter.getStakeTxParams(provider, { // ... other params queryId: 12345 // Associate with this ID }); ``` -------------------------------- ### Swap TON to Jetton using pTON Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/pton.md Example of how to perform a swap from native TON to a Jetton token, utilizing pTON as an intermediate contract. Requires a configured router and pTON instance. ```typescript const router = DEX.v2_2.Router.CPI.create(routerAddress); const ptonV2_1 = DEX.v2_2.pTON; // Swap TON → Jetton const swapTxParams = await router.getSwapTonToJettonTxParams(provider, { userWalletAddress: userAddress, proxyTon: ptonV2_1, askJettonAddress: jettonAddress, offerAmount: "1000000000", // 1 TON minAskAmount: "900000000" }); await sender.send(swapTxParams); ``` -------------------------------- ### Swap Jetton to TON using pTON Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/pton.md Example of how to perform a swap from a Jetton token to native TON, utilizing pTON as an intermediate contract. Requires a configured router and pTON instance. ```typescript const router = DEX.v2_2.Router.CPI.create(routerAddress); const ptonV2_1 = DEX.v2_2.pTON; // Swap Jetton → TON const swapTxParams2 = await router.getSwapJettonToTonTxParams(provider, { userWalletAddress: userAddress, offerJettonAddress: jettonAddress, proxyTon: ptonV2_1, offerAmount: "1000000000", minAskAmount: "900000000" // 0.9 TON }); await sender.send(swapTxParams2); ``` -------------------------------- ### Stake STON Tokens with STON.fi SDK Source: https://github.com/ston-fi/sdk/blob/main/packages/stake-sdk/README.md Example of staking 1 STON for 3 months using the STON.fi Stake SDK. Requires wallet mnemonic and STON stake contract address. ```typescript import { MONTH_IN_SECONDS, StakeNftMinter } from "@ston-fi/stake-sdk"; import { mnemonicToPrivateKey } from "@ton/crypto"; import { TonClient, WalletContractV5R1, toNano } from "@ton/ton"; const tonApiClient = new TonClient({ endpoint: "https://toncenter.com/api/v2/jsonRPC", }); const walletKeyPair = await mnemonicToPrivateKey( // replace with your mnemonic words ["your", "mnemonic", "words", "here"] ); const wallet = tonApiClient.open( // be sure to use the correct wallet version (v4/v5/etc) WalletContractV5R1.create({ workchain: 0, publicKey: walletKeyPair.publicKey, }), ); const STAKE_CONTRACT_ADDRESS = "EQATQPeCwtMzQ9u54nTjUNcK4n_0VRSxPOOROLf_IE0OU3XK"; // STON stake contract const STAKE_JETTON_ADDRESS = "EQA2kCVNwVsil2EM2mB0SkXytxCqQjS4mttjDpnXmwG9T6bO"; // STON jetton minter const stakeContract = tonApiClient.open( StakeNftMinter.create(STAKE_CONTRACT_ADDRESS), ); await stakeContract.sendStake( wallet.sender(walletKeyPair.secretKey), { jettonAddress: STAKE_JETTON_ADDRESS, userWalletAddress: wallet.address, jettonAmount: toNano("1"), // 1 STON durationSeconds: MONTH_IN_SECONDS * 3, // min - 3; max - 24 months } ); ``` -------------------------------- ### Example: Transferring TON with pTON Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/pton.md Demonstrates how to initiate a TON transfer using the pTON contract, including specifying the amount, destination, refund address, and an optional forward payload for DEX operations. ```typescript const ptonV2_1 = PtonV2_1.create("EQA..."); const txParams = await ptonV2_1.getTonTransferTxParams(provider, { tonAmount: "1000000000", // 1 TON destinationAddress: routerAddress, refundAddress: userAddress, forwardPayload: swapPayload, forwardTonAmount: "300000000" // 0.3 TON }); await sender.send(txParams); ``` -------------------------------- ### Provide Liquidity using DEX v2.2 Router Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/README.md Shows how to obtain transaction parameters for providing liquidity to a pool using the DEX v2.2 router. Requires provider and sender setup. ```typescript const txParams = await router.getProvideLiquidityJettonTxParams(provider, { userWalletAddress: userAddress, sendTokenAddress: tokenA, otherTokenAddress: tokenB, sendAmount: "1000000000", minLpOut: "995000000" }); await sender.send(txParams); ``` -------------------------------- ### Call Get Method with Caching Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/client.md Demonstrates how to use the optimized `callGetMethod` to retrieve a Jetton wallet address. The method automatically attempts to use the STON.fi API cache before falling back to the standard TON RPC. ```typescript import { Client } from "@ston-fi/sdk"; import { Address } from "@ton/ton"; const client = new Client({ endpoint: "https://toncenter.com/api/v2/jsonRPC", }); // Get wallet address with automatic caching const walletAddress = await client.callGetMethod( Address.parse("EQA..."), "get_wallet_address", [{ type: "slice", cell: ... }] ); ``` -------------------------------- ### Get Jetton-to-Jetton Swap Transaction Parameters Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/dex-v2_2.md Builds transaction parameters for swapping between two Jetton tokens. Ensure all required parameters like user wallet, offer/ask Jetton addresses, and amounts are provided. Optional parameters can specify receiver, refund, and referral details. ```typescript public async getSwapJettonToJettonTxParams( provider: ContractProvider, params: { userWalletAddress: AddressType; receiverAddress?: AddressType; offerJettonAddress: AddressType; offerJettonWalletAddress?: AddressType; askJettonAddress: AddressType; askJettonWalletAddress?: AddressType; offerAmount: AmountType; minAskAmount: AmountType; refundAddress?: AddressType; excessesAddress?: AddressType; referralAddress?: AddressType; referralValue?: AmountType; dexCustomPayload?: Cell; dexCustomPayloadForwardGasAmount?: AmountType; refundPayload?: Cell; refundForwardGasAmount?: AmountType; deadline?: number; gasAmount?: AmountType; forwardGasAmount?: AmountType; queryId?: QueryIdType; jettonCustomPayload?: Cell; transferExcessAddress?: AddressType; } ): Promise ``` ```typescript const txParams = await router.getSwapJettonToJettonTxParams(provider, { userWalletAddress: "EQA...", offerJettonAddress: "EQB...", // USDT askJettonAddress: "EQC...", // USDC offerAmount: "1000000000", // 1000 USDT (9 decimals) minAskAmount: "990000000" // Accept minimum 990 USDC }); await sender.send(txParams); ``` -------------------------------- ### Example of Flexible Amount Type Usage Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/types.md Demonstrates equivalent ways to define amounts using AmountType. For TON, the toNano() helper function should be used to convert to the smallest unit. ```typescript import { toNano } from "@ton/ton"; // All equivalent const amount1: AmountType = "1000000000"; // 1 token (9 decimals) const amount2: AmountType = 1000000000n; // BigInt const amount3: AmountType = 1000000000; // Number // For TON, use toNano() const tonAmount = toNano("1"); // "1000000000" nanoTons ``` -------------------------------- ### Get TON-to-Jetton Swap Transaction Parameters Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/dex-v2_2.md Constructs transaction parameters for swapping TON to Jetton tokens using the pTON contract. Essential parameters include user wallet, pTON instance, Jetton address, and swap amounts. Additional options for receiver, refund, and forward gas are available. ```typescript public async getSwapTonToJettonTxParams( provider: ContractProvider, params: { userWalletAddress: AddressType; proxyTon: AbstractPton; askJettonAddress: AddressType; offerAmount: AmountType; minAskAmount: AmountType; receiverAddress?: AddressType; refundAddress?: AddressType; excessesAddress?: AddressType; forwardGasAmount?: AmountType; queryId?: QueryIdType; // ... other params from getSwapJettonToJettonTxParams } ): Promise ``` -------------------------------- ### Get Jetton-to-TON Swap Transaction Parameters Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/dex-v2_2.md Generates transaction parameters for swapping Jetton tokens to TON via the pTON contract. Requires the pTON contract instance, Jetton address, and swap amounts. Optional parameters include receiver and refund addresses. ```typescript public async getSwapJettonToTonTxParams( provider: ContractProvider, params: { userWalletAddress: AddressType; offerJettonAddress: AddressType; proxyTon: AbstractPton; offerAmount: AmountType; minAskAmount: AmountType; receiverAddress?: AddressType; refundAddress?: AddressType; excessesAddress?: AddressType; gasAmount?: AmountType; forwardGasAmount?: AmountType; // ... other params same as getSwapJettonToJettonTxParams } ): Promise ``` -------------------------------- ### Get Jetton Liquidity Transaction Parameters Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/dex-v2_2.md Use this method to obtain the transaction parameters for providing liquidity using two Jetton tokens. Ensure all required parameters like user wallet address, token addresses, amounts, and minimum LP out are provided. ```typescript public async getProvideLiquidityJettonTxParams( provider: ContractProvider, params: { userWalletAddress: AddressType; sendTokenAddress: AddressType; otherTokenAddress: AddressType; sendAmount: AmountType; minLpOut: AmountType; receiverAddress?: AddressType; refundAddress?: AddressType; excessesAddress?: AddressType; gasAmount?: AmountType; forwardGasAmount?: AmountType; dexCustomPayload?: Cell; dexCustomPayloadForwardGasAmount?: AmountType; deadline?: number; queryId?: QueryIdType; jettonCustomPayload?: Cell; transferExcessAddress?: AddressType; } ): Promise ``` -------------------------------- ### Swap Jettons using DEX v2.2 Router Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/README.md Demonstrates how to get transaction parameters for swapping one jetton for another using the DEX v2.2 CPI router. Ensure you have the provider and sender configured. ```typescript import { DEX } from "@ston-fi/sdk"; const router = DEX.v2_2.Router.CPI.create(routerAddress); const txParams = await router.getSwapJettonToJettonTxParams(provider, { userWalletAddress: userAddress, offerJettonAddress: tokenA, askJettonAddress: tokenB, offerAmount: "1000000000", minAskAmount: "990000000" }); await sender.send(txParams); ``` -------------------------------- ### Typical Jetton Workflow Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/jetton.md Demonstrates the standard sequence for interacting with Jetton tokens, from obtaining the minter to checking a user's balance and wallet data. Ensure you have the necessary provider and user address. ```typescript import { JettonMinter, JettonWallet } from "@ston-fi/sdk"; // 1. Get minter for a token const usdtMinter = JettonMinter.create("EQA..."); // 2. Get the user's wallet for that token const userWalletAddress = await usdtMinter.getWalletAddress( provider, userAddress ); // 3. Create wallet instance const userWallet = JettonWallet.create(userWalletAddress); // 4. Check balance const balance = await userWallet.getBalance(provider); // 5. Get full wallet data const walletData = await userWallet.getWalletData(provider); ``` -------------------------------- ### Get Single-Side Jetton Liquidity Transaction Parameters Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/dex-v2_2.md Use this function to get transaction parameters for single-sided liquidity provision with a Jetton token. The router will automatically swap a portion for the other token in the pool. Key parameters include token addresses, amounts, and minimum LP out. ```typescript public async getSingleSideProvideLiquidityJettonTxParams( provider: ContractProvider, params: { userWalletAddress: AddressType; sendTokenAddress: AddressType; otherTokenAddress: AddressType; sendAmount: AmountType; minLpOut: AmountType; // ... other params from getProvideLiquidityJettonTxParams } ): Promise ``` -------------------------------- ### Create Jetton Instances using create() Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/jetton.md Demonstrates creating instances of JettonMinter and JettonWallet contracts using the static `create()` method, which is a convenient way to initialize contract objects. ```typescript import { JettonMinter, JettonWallet } from "@ston-fi/sdk"; const minter = JettonMinter.create("EQA..."); const wallet = JettonWallet.create("EQB..."); ``` -------------------------------- ### FarmNftMinterV3 - sendDepositNft Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/farm.md A convenience method that combines getting deposit transaction parameters and sending the transaction. ```APIDOC ## FarmNftMinterV3 - sendDepositNft ### Description A convenience method that combines getting deposit transaction parameters and sending the transaction. ### Method `public async sendDepositNft( provider: ContractProvider, via: Sender, params: Parameters[1] ): Promise` ### Parameters #### Path Parameters (None) #### Query Parameters (None) #### Request Body (Not applicable, parameters are passed directly) **Parameters:** - **provider** (ContractProvider) - Required - The contract provider. - **via** (Sender) - Required - The sender to use for the transaction. - **params** (Parameters[1]) - Required - Parameters for the deposit, matching `getDepositNftTxParams`. ### Request Example (Not applicable, this method sends the transaction) ### Response #### Success Response - **Transaction** - The transaction result. ``` -------------------------------- ### sendDepositNft Method Signature Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/farm.md A convenience method that combines getting transaction parameters and sending the deposit transaction. ```typescript public async sendDepositNft( provider: ContractProvider, via: Sender, params: Parameters[1] ): Promise ``` -------------------------------- ### Create pTON Instances Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/pton.md Demonstrates how to create instances of pTON contracts, including the recommended v2.1 version and the older v1 version, using the Ston.fi SDK. ```typescript import { DEX, pTON_VERSION } from "@ston-fi/sdk"; // v2.1 (recommended) const ptonV2_1 = DEX.v2_2.pTON.create("EQA..."); // Or from farm/dex packages const ptonV2_1Alt = DEX.pTON.v2_1.create("EQA..."); const ptonV1 = DEX.pTON.v1.create("EQA..."); ``` -------------------------------- ### sendDeployWallet Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/pton.md Sends a transaction to deploy a pTON wallet. This is a convenience method that wraps the process of getting transaction parameters and sending them. ```APIDOC ## POST /sendDeployWallet ### Description Sends a transaction to deploy a pTON wallet. This is a convenience method that wraps the process of getting transaction parameters and sending them. ### Method POST ### Endpoint /sendDeployWallet ### Parameters #### Request Body - **provider** (ContractProvider) - Required - **via** (Sender) - Required - **params** (object) - Required - Parameters for wallet deployment, same as `getDeployWalletTxParams` - **params.ownerAddress** (AddressType) - Required - Wallet owner - **params.excessAddress** (AddressType) - Required - Where to send gas excess - **params.gasAmount** (AmountType) - Optional - Deployment gas (Default: 0.1 TON) - **params.queryId** (QueryIdType) - Optional - Query ID (Default: 0) ### Response #### Success Response (200) - **Transaction** (object) - Details of the sent deployment transaction ``` -------------------------------- ### Create Jetton Instances using Constructor Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/jetton.md Shows how to create instances of JettonMinter and JettonWallet contracts by directly using their constructors, passing the contract address as an argument. ```typescript const minter = new JettonMinter("EQA..."); const wallet = new JettonWallet("EQB..."); ``` -------------------------------- ### Instantiating Farm Contracts Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/farm.md Demonstrates how to create instances of FarmNftMinter and FarmNftItem contracts for v3, v2, and v1 using the STON.fi SDK. ```typescript import { FARM } from "@ston-fi/sdk"; // v3 (recommended) const farmMinterV3 = FARM.v3.FarmNftMinter.create(farmAddress); const farmItemV3 = FARM.v3.FarmNftItem.create(nftAddress); // v2 const farmMinterV2 = FARM.v2.FarmNftMinter.create(farmAddress); const farmItemV2 = FARM.v2.FarmNftItem.create(nftAddress); // v1 const farmMinterV1 = FARM.v1.FarmNftMinter.create(farmAddress); ``` -------------------------------- ### Get Destroy NFT Transaction Parameters Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/stake-nft.md Builds the transaction parameters for destroying the NFT. Use this to prepare a transaction that will permanently remove the NFT. ```typescript const destroyTxParams = await nftItem.getDestroyTxParams(provider); ``` -------------------------------- ### Accessing V2.2 Contracts via routerFactory helper Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/dex-v2_2.md Illustrates how to instantiate a V2.2 router using the `routerFactory` helper, providing address, version, and router type. ```APIDOC ## Accessing v2.2 Contracts via routerFactory helper ### Description This section explains how to use the `routerFactory` helper to create a V2.2 router instance by providing its address, major and minor versions, and router type. ### Usage ```typescript import { routerFactory } from "@ston-fi/sdk"; const router = routerFactory({ address: routerAddress, majorVersion: 2, minorVersion: 2, routerType: "constant_product" }); ``` ``` -------------------------------- ### Get Pool Reserves Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/utilities.md Retrieves token reserves and fees from a BasePoolV2_2 contract. Converts reserves to base units using provided decimals. ```typescript import { toUnits } from "@ston-fi/sdk"; async function getPoolReserves( pool: BasePoolV2_2, provider: ContractProvider, decimals0: number, decimals1: number ) { const data = await pool.getPoolData(provider); return { token0Reserve: toUnits(data.reserve0, decimals0), token1Reserve: toUnits(data.reserve1, decimals1), lpFee: data.lpFee, protocolFee: data.protocolFee }; } ``` -------------------------------- ### Client Constructor Options Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/configuration.md Defines the options for initializing the STON.fi Client, including RPC endpoint, API key, and custom STON.fi API client. ```typescript interface ClientOptions extends TonClientOptions { endpoint: string; // RPC endpoint URL (required) key?: string; // Optional API key stonApiClient?: StonApiClient; // Custom STON.fi API client } ``` -------------------------------- ### Get Restake Transaction Parameters Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/stake-nft.md Generates the transaction parameters to extend the stake duration of an active position. Allows specifying a new duration in seconds. ```typescript const sixtyDays = 60 * 24 * 60 * 60; const restakeTxParams = await nftItem.getRestakeTxParams(provider, { durationSeconds: sixtyDays }); await sender.send(restakeTxParams); ``` -------------------------------- ### Get pTON Wallet Address Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/pton.md Retrieves the pTON wallet address associated with a given owner address. This function is part of the pTON contract interface. ```typescript public async getWalletAddress( provider: ContractProvider, ownerAddress: AddressType ): Promise
``` -------------------------------- ### Get Jetton Wallet Balance Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/jetton.md Retrieves the current balance of Jetton tokens held within this wallet. The balance is returned in the smallest units of the token. ```typescript public async getBalance( provider: ContractProvider ): Promise ``` ```typescript import { JettonWallet } from "@ston-fi/sdk"; const jettonWallet = JettonWallet.create("EQB..."); const balance = await jettonWallet.getBalance(provider); console.log("Wallet balance:", balance.toString()); ``` -------------------------------- ### Create Stake NFT Minter and Item Instances Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/stake-nft.md Use StakeNftMinter.create() to initialize a minter instance and StakeNftItem.create() to initialize an NFT item instance. These are the entry points for interacting with the staking contract. ```typescript import { StakeNftMinter, StakeNftItem } from "@ston-fi/stake-sdk"; // Minter const minter = StakeNftMinter.create("EQA..."); // NFT item const nftItem = StakeNftItem.create("EQB..."); ``` -------------------------------- ### Get Claim Rewards Transaction Parameters Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/stake-nft.md Builds the transaction parameters necessary to claim accumulated staking rewards. This function prepares the transaction payload for claiming. ```typescript const claimRewardsTxParams = await nftItem.getClaimRewardsTxParams(provider); ``` -------------------------------- ### Complete Staking Flow with Stake NFT SDK Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/stake-nft.md This snippet demonstrates the full lifecycle of staking tokens using the Stake NFT SDK. It covers creating a stake, monitoring its status, claiming rewards, extending the stake duration, and finally unstaking. Ensure you have the necessary provider and sender instances initialized. ```typescript import { StakeNftMinter, StakeNftItem, MONTH_IN_SECONDS } from "@ston-fi/stake-sdk"; // 1. Stake tokens const minter = StakeNftMinter.create(minerAddress); const stakeTxParams = await minter.getStakeTxParams(provider, { userWalletAddress: userAddress, jettonAddress: tokenAddress, jettonAmount: "1000000000", // 1 token durationSeconds: MONTH_IN_SECONDS, nftRecipient: userAddress }); const stakeTx = await sender.send(stakeTxParams); const nftAddress = getAddressFromTransaction(stakeTx); // Extract from events // 2. Monitor stake const nftItem = StakeNftItem.create(nftAddress); const nftData = await nftItem.getNftData(provider); console.log("Rewards:", nftData.claimableRewards.toString()); // 3. Claim rewards (without unstaking) const claimTxParams = await nftItem.getClaimRewardsTxParams(provider); await sender.send(claimTxParams); // 4. Extend stake const restakeTxParams = await nftItem.getRestakeTxParams(provider, { durationSeconds: MONTH_IN_SECONDS * 2 }); await sender.send(restakeTxParams); // 5. Unstake const unstakeTxParams = await nftItem.getUnstakeTxParams(provider); await sender.send(unstakeTxParams); ``` -------------------------------- ### Get Minter Data Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/stake-nft.md Retrieves the current configuration and state of the staking pool managed by the minter contract. This includes addresses, amounts, and total staked values. ```typescript public async getMinterData( provider: ContractProvider ): Promise<{ nftCollectionAddress: Address; jettonMinterAddress: Address; jettonWalletAddress: Address; minStakingAmount: bigint; maxStakingAmount: bigint; totalStaked: bigint; totalRewardEmitted: bigint; // ... other fields }> ``` -------------------------------- ### Get Jetton Wallet Address Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/jetton.md Retrieves the Jetton wallet address associated with a specific owner's address. Throws an error if the minter contract is inactive. ```typescript public async getWalletAddress( provider: ContractProvider, ownerAddress: AddressType ): Promise
``` ```typescript import { JettonMinter } from "@ston-fi/sdk"; const jettonMinter = JettonMinter.create("EQA..."); const walletAddress = await jettonMinter.getWalletAddress(provider, userAddress); console.log("User's USDT wallet:", walletAddress); ``` -------------------------------- ### Configure DEX Router with Default Gas Constants Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/README.md Shows how to create a DEX router instance using default gas constants. This is the recommended approach for most use cases. ```typescript import { DEX } from "@ston-fi/sdk"; // Use defaults (recommended) const router = DEX.v2_2.Router.CPI.create(address); ``` -------------------------------- ### Reuse Client Instance Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/configuration.md Demonstrates the best practice of creating and reusing a single Client instance for multiple operations to improve efficiency. ```typescript // Good: Create once, reuse const client = new Client({ endpoint: "https://toncenter.com/api/v2/jsonRPC" }); // Use client for all operations const data1 = await client.get(address1, "method1", []); const data2 = await client.get(address2, "method2", []); ``` -------------------------------- ### Get Pool Instance Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/dex-v2_2.md Retrieves a BasePoolV2_2 instance for a given token pair. Throws an error if the pool does not exist. Ensure the provider and token addresses are correctly specified. ```typescript public async getPool( provider: ContractProvider, params: { token0: AddressType; token1: AddressType; } ): Promise ``` ```typescript const router = BaseRouterV2_2.create("EQA..."); const pool = await router.getPool(provider, { token0: "EQA...", token1: "EQB..." }); ``` -------------------------------- ### Get NFT Stake Data Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/stake-nft.md Retrieves the current details of a stake position, including staked amount, claimable rewards, and status. Useful for monitoring active stakes. ```typescript const nftData = await nftItem.getNftData(provider); console.log("Staked amount:", nftData.amountStaked.toString()); console.log("Claimable rewards:", nftData.claimableRewards.toString()); console.log("Status:", nftData.status === StakeNftItemStatus.ACTIVE ? "ACTIVE" : "INACTIVE"); ``` -------------------------------- ### PtonV2_1 Constructor Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/pton.md Initializes a new PtonV2_1 contract instance. It requires the contract address and optionally accepts configuration options for gas constants. ```APIDOC ## Constructor PtonV2_1 ### Description Initializes a new PtonV2_1 contract instance. It requires the contract address and optionally accepts configuration options for gas constants. ### Parameters #### Path Parameters - **address** (AddressType) - Required - pTON contract address #### Options - **options** (PtonV2_1Options) - Optional - Configuration options - **options.gasConstants** (Partial) - Optional - Override default gas amounts ``` -------------------------------- ### Get Unstake Transaction Parameters Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/stake-nft.md Builds the transaction parameters required to unstake tokens and exit a staking position. Use this when you need to construct the transaction manually before sending. ```typescript const nftItem = StakeNftItem.create("EQB..."); const unstakeTxParams = await nftItem.getUnstakeTxParams(provider); await sender.send(unstakeTxParams); ``` -------------------------------- ### Use Different Endpoints for Production and Testing Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/configuration.md Demonstrates configuring separate Client instances for production and testing environments, utilizing different RPC endpoints and API keys. ```typescript // For production const productionClient = new Client({ endpoint: "https://toncenter.com/api/v2/jsonRPC", key: process.env.TON_RPC_KEY }); // For testing const testClient = new Client({ endpoint: "https://testnet.toncenter.com/api/v2/jsonRPC" }); ``` -------------------------------- ### Get Jetton Wallet Data Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/jetton.md Fetches the complete state of the Jetton wallet, including its balance, owner address, associated minter address, and wallet contract code. ```typescript public async getWalletData( provider: ContractProvider ): Promise<{ balance: bigint; ownerAddress: Address; jettonMasterAddress: Address; jettonWalletCode: Cell; }> ``` ```typescript const walletData = await jettonWallet.getWalletData(provider); console.log("Owner:", walletData.ownerAddress.toString()); console.log("Token:", walletData.jettonMasterAddress.toString()); console.log("Balance:", walletData.balance.toString()); ``` -------------------------------- ### Per-Transaction Configuration Override Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/configuration.md Example of overriding default gas amounts and transaction deadlines for a specific swap operation. Custom deadline is set in Unix timestamp format. ```typescript const swapTxParams = await router.getSwapJettonToJettonTxParams(provider, { // ... swap params ... gasAmount: toNano("0.5"), // Override gas for this tx forwardGasAmount: toNano("0.4"), // Override forward gas deadline: Math.floor(Date.now() / 1000) + 600 // Custom deadline }); ``` -------------------------------- ### Import Core Utilities Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/utilities.md Import the `fromUnits` and `toUnits` functions for handling token amounts. These utilities support both string and bigint inputs. ```typescript // Core utilities import { fromUnits, toUnits, } from "@ston-fi/sdk"; ``` -------------------------------- ### Get pTON Wallet Data Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/pton.md Fetches the current state of a pTON contract, including balance, owner address, and master addresses. This function is part of the pTON contract interface. ```typescript public async getWalletData( provider: ContractProvider ): Promise<{ balance: bigint; ownerAddress: Address; ptonMasterAddress: Address; ptonWalletCode: Cell; }> ``` -------------------------------- ### Get Jetton Data Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/jetton.md Fetches comprehensive token metadata and configuration, including total supply, admin address, and contract codes. Useful for understanding the token's state. ```typescript public async getJettonData( provider: ContractProvider ): Promise<{ totalSupply: bigint; canIncSupply: boolean; adminAddress: Address | null; contentRaw: Cell; jettonWalletCode: Cell; }> ``` ```typescript const jettonData = await jettonMinter.getJettonData(provider); console.log("Total supply:", jettonData.totalSupply.toString()); console.log("Admin:", jettonData.adminAddress?.toString()); ``` -------------------------------- ### Import Core SDK Components Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/README.md Import necessary classes and functions for DEX trading, staking, and utilities from the STON.fi SDK. ```typescript import { DEX, dexFactory, routerFactory } from "@ston-fi/sdk"; // Staking import { StakeNftMinter, StakeNftItem } from "@ston-fi/stake-sdk"; // Utilities import { Client, fromUnits, toUnits } from "@ston-fi/sdk"; ``` -------------------------------- ### Unstake Position with STON.fi SDK and TonConnect Source: https://github.com/ston-fi/sdk/blob/main/packages/stake-sdk/README.md Example of unstaking a position using the STON.fi Stake SDK and TonConnect UI. This builds an unstake transaction message and sends it for signing. ```tsx import { MONTH_IN_SECONDS, StakeNftItem } from "@ston-fi/stake-sdk"; import { TonClient } from "@ton/ton"; import { useTonConnectUI } from "@tonconnect/ui-react"; const tonApiClient = new TonClient({ endpoint: "https://toncenter.com/api/v2/jsonRPC", }); const STAKE_NFT_ADDRESS = "" // put your nft address here const stakeNftContract = tonApiClient.open( StakeNftItem.create(STAKE_NFT_ADDRESS), ); function UnstakeAction() { const [tonConnectUI] = useTonConnectUI(); return ( ) } ``` -------------------------------- ### Custom API Client for Jetton Queries Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/configuration.md Shows how to integrate a custom StonApiClient for specific API interactions, such as Jetton queries, by passing it during Client instantiation. ```typescript import { Client } from "@ston-fi/sdk"; import { StonApiClient } from "@ston-fi/api"; const apiClient = new StonApiClient({ baseUrl: "https://api.ston.fi" }); const client = new Client({ endpoint: "...", stonApiClient: apiClient }); ``` -------------------------------- ### Send Swap Jetton to Jetton Transaction Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/dex-v2_2.md Helper method to send a swap transaction from Jetton to Jetton. This combines getting transaction parameters and sending the transaction via a provided sender. ```typescript public async sendSwapJettonToJetton( provider: ContractProvider, via: Sender, params: Parameters<...getSwapJettonToJettonTxParams>[1] ): Promise ``` -------------------------------- ### Client Class Constructor Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/client.md Initializes the STON.fi Client, extending TonClient with optional STON.fi API client for caching. ```APIDOC ## Class: Client ### Constructor **Parameters:** * **options** (object) - Required. TonClient configuration options. * **options.endpoint** (string) - Required. RPC endpoint URL. * **options.key** (string) - Optional. API key for endpoint authentication. * **options.stonApiClient** (StonApiClient) - Optional. Custom STON.fi API client instance for caching wallet address queries. Defaults to `new StonApiClient()`. ``` -------------------------------- ### Handle Token Amounts with fromUnits and toUnits Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/README.md Demonstrates the usage of `fromUnits` and `toUnits` helper functions for converting between human-readable amounts and the smallest internal units. Ensure the correct decimals are used for the conversion. ```typescript import { fromUnits, toUnits } from "@ston-fi/sdk"; // Parse user input: "1.5 tokens" const amount = fromUnits("1.5", 9); // "1500000000" // Display to user: 1,500,000,000 tokens const display = toUnits(amount, 9); // "1.5" ``` -------------------------------- ### Accessing DEX V2.2 Contracts via DEX Namespace Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/dex-v2_2.md Demonstrates how to import and access v2.2 DEX contracts using the DEX namespace from the SDK. Shows instantiation of various router types, pools, LpAccounts, and Vaults. ```typescript import { DEX } from "@ston-fi/sdk"; // Get v2.2 contracts const dexV2_2 = DEX.v2_2; // Instantiate router by type const cpiRouter = dexV2_2.Router.CPI.create(address); const stableRouter = dexV2_2.Router.Stable.create(address); const wcpiRouter = dexV2_2.Router.WCPI.create(address); const wstableRouter = dexV2_2.Router.WStable.create(address); // Via deprecated generic Router class const router = dexV2_2.Router.create(address); // Get pool const pool = dexV2_2.Pool.CPI.create(poolAddress); // Get LpAccount const lpAccount = dexV2_2.LpAccount.create(lpAccountAddress); // Get Vault const vault = dexV2_2.Vault.create(vaultAddress); ``` -------------------------------- ### PtonV2_1 Constructor Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/pton.md Initializes a PtonV2_1 contract instance. Requires the contract address and accepts optional configuration for gas constants. ```typescript constructor( address: AddressType, options?: PtonV2_1Options ) ``` -------------------------------- ### Accessing V2.2 Contracts via DEX namespace Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/dex-v2_2.md Demonstrates how to access V2.2 DEX contracts, including routers, pools, LpAccounts, and Vaults, using the `DEX` namespace from the SDK. ```APIDOC ## Accessing v2.2 Contracts via DEX namespace ### Description This section shows how to instantiate V2.2 contract objects like routers, pools, LpAccounts, and Vaults using the `DEX` object from the SDK. ### Usage ```typescript import { DEX } from "@ston-fi/sdk"; // Get v2.2 contracts const dexV2_2 = DEX.v2_2; // Instantiate routers by type const cpiRouter = dexV2_2.Router.CPI.create(address); const stableRouter = dexV2_2.Router.Stable.create(address); const wcpiRouter = dexV2_2.Router.WCPI.create(address); const wstableRouter = dexV2_2.Router.WStable.create(address); // Via deprecated generic Router class const router = dexV2_2.Router.create(address); // Get pool const pool = dexV2_2.Pool.CPI.create(poolAddress); // Get LpAccount const lpAccount = dexV2_2.LpAccount.create(lpAccountAddress); // Get Vault const vault = dexV2_2.Vault.create(vaultAddress); ``` ``` -------------------------------- ### PtonV2_1 Options Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/configuration.md Configuration options for PtonV2_1, including gas constants for TON transfers and wallet deployment. ```typescript interface PtonV2_1Options extends PtonV1Options { gasConstants?: Partial; } ``` -------------------------------- ### Get Vault Instance Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/api-reference/dex-v2_2.md Retrieves a VaultV2_2 instance for a user and a specific token. This instance is used for managing user deposits. Requires the user's wallet address and the token's minter address. ```typescript public async getVault( provider: ContractProvider, params: { user: AddressType; tokenMinter: AddressType; } ): Promise ``` -------------------------------- ### Configuration Validation: Referral Fee Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/configuration.md Illustrates configuration validation, specifically showing an error when the referral fee exceeds the maximum allowed value (100 BPS). ```typescript // Referral fee must be in [0, 100] BPS await router.getSwapJettonToJettonTxParams(provider, { referralValue: 150 // ❌ Error: must be <= 100 }); ``` -------------------------------- ### Handle Insufficient Gas with Default or Increased Amounts Source: https://github.com/ston-fi/sdk/blob/main/_autodocs/errors.md Demonstrates how to handle insufficient gas errors by either using default gas amounts or manually increasing `gasAmount` and `forwardGasAmount` for swap transactions. ```typescript import { toNano } from "@ton/ton"; // Use defaults (recommended) const txParams = await router.getSwapJettonToJettonTxParams(provider, { // Don't override, use defaults } ); // Or increase manually const txParams = await router.getSwapJettonToJettonTxParams(provider, { gasAmount: toNano("0.5"), // Higher than default 0.3 forwardGasAmount: toNano("0.4") // Higher than default 0.24 } ); ```