Swap (v2)
Execute swaps on STON.fi v2 - enhanced routing with vault mechanics for optimal rates
Mainnet-first workflow
import { dexFactory, Client } from "@ston-fi/sdk";
import { StonApiClient } from "@ston-fi/api";
const tonClient = new Client({
endpoint: "https://toncenter.com/api/v2/jsonRPC",
});
const apiClient = new StonApiClient();
// 1. Simulate the swap to discover routing details
const simulationResult = await apiClient.simulateSwap({
offerAddress: "<from asset address or 'ton'>",
askAddress: "<to asset address>",
offerUnits: "<amount in blockchain units>",
slippageTolerance: "0.01",
});
// 2. Router metadata ships with the simulation result
const { router: routerInfo } = simulationResult;
const dexContracts = dexFactory(routerInfo);
// 3. Open the router contract
const router = tonClient.open(
dexContracts.Router.create(routerInfo.address)
);
// Optional helper when TON is part of the route
const proxyTon = dexContracts.pTON.create(routerInfo.ptonMasterAddress);Swap TON to jetton
Swap jetton to jetton
Swap jetton to TON
Testnet swaps (manual setup)
Last updated