{"format":"opendoc-document","version":1,"url":"https://docs.storm.tg/developers/sdk_js_v2","title":"JavaScript SDK: V2 wallet transactions","description":"@storm trade/trading sdk builds Storm v2 transactions: market, limit and stop orders, Stop Loss and Take Profit, margin changes, liquidity operations.","kind":"article","locale":"en","inLanguage":"en","lastModified":"2026-10-09T14:26:32+03:00","revision":"d36475e7b456c737fae6933fa27b7e1bc2687f2c19291b05725ab2c4e8f79d7a","section":{"title":"For Developers","url":"https://docs.storm.tg/developers"},"representations":{"html":"https://docs.storm.tg/developers/sdk_js_v2","markdown":"https://docs.storm.tg/developers/sdk_js_v2.md","json":"https://docs.storm.tg/developers/sdk_js_v2.json"},"translations":{"en":"https://docs.storm.tg/developers/sdk_js_v2"},"breadcrumbs":[{"title":"⚡ About Storm Trade","url":"https://docs.storm.tg"},{"title":"For Developers","url":"https://docs.storm.tg/developers"},{"title":"JavaScript SDK: V2 wallet transactions","url":"https://docs.storm.tg/developers/sdk_js_v2"}],"headings":[{"depth":2,"id":"install","title":"📦 Install"},{"depth":2,"id":"initialize","title":"🚀 Initialize"},{"depth":2,"id":"orders","title":"📈 Orders"},{"depth":2,"id":"positions","title":"🧾 Positions"},{"depth":2,"id":"liquidity","title":"💧 Liquidity"},{"depth":2,"id":"sending-the-transaction","title":"📤 Sending the Transaction"},{"depth":2,"id":"examples-in-the-repository","title":"🧑‍💻 Examples in the Repository"}],"markdown":"# JavaScript SDK: V2 wallet transactions\n\n`@storm-trade/trading-sdk` builds Storm **v2** transactions: market, limit and stop orders, Stop-Loss and Take-Profit, margin changes, liquidity operations. Every method returns transaction parameters (`to`, `value`, `body`), and you send them with the wallet of your choice: TON Connect in the browser or a `@ton/ton` wallet contract in Node.js.\n\nFor Smart Accounts and signed intents, use the [JavaScript V3 guide](sdk_js.md). This page covers the existing V2 exports.\n\n- npm: [@storm-trade/trading-sdk](https://www.npmjs.com/package/@storm-trade/trading-sdk)\n- Source and runnable examples: [storm-trade/sdk-js](https://github.com/storm-trade/sdk-js), folder `src/examples`\n\n---\n\n## 📦 Install\n\n```bash\nnpm install @storm-trade/trading-sdk @ton/ton\n```\n\n---\n\n## 🚀 Initialize\n\nThis example uses Mainnet. For testing, obtain testnet endpoints during [builder onboarding](https://app.storm.tg/builders) and configure the API, oracle and TON RPC for that network together.\n\n```typescript\nimport { TonClient } from '@ton/ton';\nimport { StormTradingSdk } from '@storm-trade/trading-sdk/sdk';\nimport { StormClient, OracleClient } from '@storm-trade/trading-sdk/api-clients';\n\nconst ORACLE_URL = 'https://oracle.storm.tg';\nconst STORM_API_URL = 'https://api.storm.tg/api';\nconst TON_CENTER = 'https://toncenter.com/api/v2/jsonRPC';\n\nconst tonClient = new TonClient({ endpoint: TON_CENTER, apiKey: TONCENTER_API_KEY });\n\nconst sdk = new StormTradingSdk(\n  new StormClient(STORM_API_URL, new OracleClient(ORACLE_URL)),\n  tonClient,\n  TRADER_ADDRESS, // the wallet that will sign, string or Address\n);\nawait sdk.init(); // loads markets, vaults and contract addresses\n```\n\n---\n\n## 📈 Orders\n\nAmounts are collateral in the asset's own decimals. Leverage and prices are scaled by 10^9.\n\n```typescript\nimport { Direction, OrderType } from '@storm-trade/trading-sdk/base-packers';\n\n// Market long, 1 TON collateral, 2x, with SL/TP created on execution\nconst open = await sdk.createMarketOpenOrder({\n  baseAssetName: 'XRP',\n  collateralAssetName: 'TON',\n  direction: Direction.long,\n  amount: 1_000_000_000n,\n  leverage: 2_000_000_000n,\n  minBaseAssetAmount: 900_000_000n,   // slippage guard, optional\n  stopTriggerPrice: 80_000_000_000n,  // optional\n  takeTriggerPrice: 120_000_000_000n, // optional\n});\n\n// Limit order\nconst limit = await sdk.createLimitOrder({\n  baseAssetName: 'XRP',\n  collateralAssetName: 'TON',\n  direction: Direction.long,\n  amount: 1_000_000_000n,\n  leverage: 2_000_000_000n,\n  limitPrice: 100_000_000_000n,\n});\n\n// Stop-market and stop-limit\nawait sdk.createStopMarketOrder({ /* ...same fields... */ stopPrice: 105_000_000_000n });\nawait sdk.createStopLimitOrder({ /* ...same fields... */ stopPrice: 105_000_000_000n, limitPrice: 106_000_000_000n });\n\n// Cancel a resting order by type and index from the position manager\nconst cancel = await sdk.cancelOrder({\n  baseAssetName: 'XRP',\n  collateralAssetName: 'TON',\n  direction: Direction.long,\n  orderType: OrderType.limit,\n  orderIndex: 0,\n});\n```\n\n---\n\n## 🧾 Positions\n\n```typescript\n// Stop-Loss / Take-Profit on an open position\nawait sdk.createStopLossOrder({ baseAssetName: 'XRP', collateralAssetName: 'TON', direction: Direction.long, amount: 1_000_000_000n, triggerPrice: 90_000_000_000n });\nawait sdk.createTakeProfitOrder({ baseAssetName: 'XRP', collateralAssetName: 'TON', direction: Direction.long, amount: 1_000_000_000n, triggerPrice: 110_000_000_000n });\n\n// Close, size is base asset with 9 decimals\nawait sdk.createClosePositionOrder({ baseAssetName: 'XRP', collateralAssetName: 'TON', direction: Direction.long, size: 1_000_000_000n });\n\n// Margin. The SDK fetches a signed oracle price for these two calls.\nawait sdk.addMargin({ baseAssetName: 'XRP', collateralAssetName: 'TON', direction: Direction.long, amount: 500_000_000n });\nawait sdk.removeMargin({ baseAssetName: 'XRP', collateralAssetName: 'TON', direction: Direction.long, amount: 200_000_000n });\n```\n\n---\n\n## 💧 Liquidity\n\n```typescript\nawait sdk.provideLiquidity({ assetName: 'USDT', amount: 1_000_000n }); // 1 USDT, 6 decimals\nawait sdk.withdrawLiquidity({ assetName: 'TON', amountOfSLP: 500_000_000n }); // 0.5 SLP\n```\n\n---\n\n## 📤 Sending the Transaction\n\nEvery call above returns `TXParams`. Nothing is sent until you hand it to a wallet.\n\n**Browser, TON Connect:**\n\n```typescript\nimport { TonConnectUI } from '@tonconnect/ui';\n\nconst tonConnectUI = new TonConnectUI({ manifestUrl: 'https://your-app.com/tonconnect-manifest.json' });\n\nconst tx = await sdk.createMarketOpenOrder({ /* ... */ });\nawait tonConnectUI.sendTransaction({\n  validUntil: Math.floor(Date.now() / 1000) + 300,\n  messages: [{\n    address: tx.to.toString(),\n    amount: tx.value.toString(),\n    payload: tx.body.toBoc().toString('base64'),\n  }],\n});\n```\n\n**Node.js, hot wallet from a mnemonic:**\n\n```typescript\nimport { internal, WalletContractV4 } from '@ton/ton';\nimport { mnemonicToPrivateKey } from '@ton/crypto';\n\nconst keyPair = await mnemonicToPrivateKey(MNEMONIC.split(' '));\nconst wallet = tonClient.open(WalletContractV4.create({ workchain: 0, publicKey: keyPair.publicKey }));\n\nconst tx = await sdk.createMarketOpenOrder({ /* ... */ });\nawait wallet.sendTransfer({\n  seqno: await wallet.getSeqno(),\n  secretKey: keyPair.secretKey,\n  messages: [internal(tx)],\n});\n```\n\nPass the wallet's address as `TRADER_ADDRESS` when constructing the SDK, otherwise the position manager lookups point at the wrong account.\n\n---\n\n## 🧑‍💻 Examples in the Repository\n\n`src/examples` in [sdk-js](https://github.com/storm-trade/sdk-js) contains runnable scripts grouped by `orders`, `liquidity` and `ton-connect`, plus a `utils/sdk-manager.ts` helper that wraps the Node.js sending pattern above. Copy the closest script and replace the environment block.\n","text":"JavaScript SDK: V2 wallet transactions @storm trade/trading sdk builds Storm v2 transactions: market, limit and stop orders, Stop Loss and Take Profit, margin changes, liquidity operations. Every method returns transaction parameters ( to , value , body ), and you send them with the wallet of your choice: TON Connect in the browser or a @ton/ton wallet contract in Node.js. For Smart Accounts and signed intents, use the JavaScript V3 guide. This page covers the existing V2 exports. npm: @storm trade/trading sdk Source and runnable examples: storm trade/sdk js, folder src/examples 🚀 Initialize This example uses Mainnet. For testing, obtain testnet endpoints during builder onboarding and configure the API, oracle and TON RPC for that network together. 📈 Orders Amounts are collateral in the asset's own decimals. Leverage and prices are scaled by 10^9. 🧾 Positions 💧 Liquidity 📤 Sending the Transaction Every call above returns TXParams . Nothing is sent until you hand it to a wallet. Browser, TON Connect: Node.js, hot wallet from a mnemonic: Pass the wallet's address as TRADER ADDRESS when constructing the SDK, otherwise the position manager lookups point at the wrong account. 🧑‍💻 Examples in the Repository src/examples in sdk js contains runnable scripts grouped by orders , liquidity and ton connect , plus a utils/sdk manager.ts helper that wraps the Node.js sending pattern above. Copy the closest script and replace the environment block."}