{"format":"opendoc-document","version":1,"url":"https://docs.storm.tg/developers/sdk_js","title":"🟨 JavaScript / TypeScript SDK","description":"Use the V3 SDK to place orders, manage positions and read Smart Account balances.","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","markdown":"https://docs.storm.tg/developers/sdk_js.md","json":"https://docs.storm.tg/developers/sdk_js.json"},"translations":{"en":"https://docs.storm.tg/developers/sdk_js"},"breadcrumbs":[{"title":"⚡ About Storm Trade","url":"https://docs.storm.tg"},{"title":"For Developers","url":"https://docs.storm.tg/developers"},{"title":"🟨 JavaScript / TypeScript SDK","url":"https://docs.storm.tg/developers/sdk_js"}],"headings":[{"depth":2,"id":"install","title":"Install"},{"depth":2,"id":"connect","title":"Connect"},{"depth":2,"id":"place-a-market-order","title":"Place a market order"},{"depth":2,"id":"check-the-result","title":"Check the result"},{"depth":2,"id":"add-sl-tp-or-use-a-limit-price","title":"Add SL/TP or use a limit price"},{"depth":2,"id":"close-a-position","title":"Close a position"},{"depth":2,"id":"cancel-an-order","title":"Cancel an order"},{"depth":2,"id":"amounts-and-account-setup","title":"Amounts and account setup"}],"markdown":"# 🟨 JavaScript / TypeScript SDK\n\nUse the V3 SDK to place orders, manage positions and read Smart Account balances.\n\n## Install\n\nThe examples use Node.js 22 and SDK **1.1.0**:\n\n```bash\nnpm install @storm-trade/trading-sdk@1.1.0 @ton/ton@^15.2.0\n```\n\n## Connect\n\nFirst, fund the user's Smart Account and register a signing key. Get the market's vAMM address from [markets](/developers/operations/listmarkets).\n\n```typescript\nimport { Address, toNano } from '@ton/ton';\nimport {\n  OrderType, V3Client, prepareOrder, prepareCancel,\n} from '@storm-trade/trading-sdk/v3';\n\nconst api = new V3Client('https://api.storm.tg/v3-node-0');\nconst smartAccount = Address.parse('YOUR_SMART_ACCOUNT');\nconst market = Address.parse('MARKET_VAMM_ADDRESS');\n```\n\nReplace the two addresses with your own. This URL is **Mainnet**. For testing, get matching API and contract addresses during [builder onboarding](https://app.storm.tg/builders).\n\nThe examples below use three values from your application:\n\n- `signer`: the registered key's 32-byte `publicKey` and a `sign(hash)` function that returns a 64-byte Ed25519 signature. It signs the cell hash directly.\n- `queryId`: an unused ID reserved for this Smart Account. The SDK does not reserve IDs for you.\n- `minimumBaseAmount`: the minimum base asset size you accept, based on your quote and slippage setting, with 9 decimals.\n\nFor complete account and signer setup, use the [runnable examples](https://github.com/storm-trade/sdk-js/tree/main/examples/builders). Wallet transaction signatures and `ton_proof` cannot replace the intent signer.\n\n## Place a market order\n\nThis opens a long position with **100 collateral and 3× leverage**:\n\n```typescript\nconst now = Math.floor(Date.now() / 1000);\nconst prepared = await prepareOrder({\n  smartAccount,\n  market,\n  signer,\n  queryId,\n  createdAt: now - 5,\n  order: {\n    type: OrderType.Market,\n    expiration: now + 600,\n    direction: 0, // 0 = long, 1 = short\n    amount: toNano('100'),\n    leverage: toNano('3'),\n    minBaseAssetAmount: minimumBaseAmount,\n    limitPrice: 0n,\n    stopTriggerPrice: 0n,\n    takeTriggerPrice: 0n,\n  },\n});\n```\n\nSave `prepared.hash`, `prepared.request` and `prepared.orderRequestHashes` in your application before sending. Then submit:\n\n```typescript\nawait api.placeOrder(prepared.request);\n```\n\nTo earn builder fees, add your registered `builder` address to `prepareOrder`. See [Builder Fees](builder_fees.md).\n\n## Check the result\n\n```typescript\nconst status = await api.getIntentStatus(prepared.hash);\nconst positions = await api.getPositions(smartAccount.toRawString());\n```\n\n`accepted` means the API received the order. Neither `accepted` nor `done` proves a fill. Confirm the result through [account bundles](/developers/operations/getaccountbundles), transactions and position state.\n\n**If a request times out, check the saved hash before creating another order.** The first order may already be accepted. The SDK does not retry automatically.\n\n## Add SL/TP or use a limit price\n\nIn the opening order above:\n\n| Action | Change |\n| --- | --- |\n| Stop loss | Set `stopTriggerPrice` to your stop price |\n| Take profit | Set `takeTriggerPrice` to your target price |\n| Limit order | Use `OrderType.Limit`, set `limitPrice`, and replace `minBaseAssetAmount` with `stopPrice: 0n` |\n| Stop market | Use `OrderType.Limit`, set `stopPrice`, keep `limitPrice: 0n`, and omit `minBaseAssetAmount` |\n| Stop limit | Use `OrderType.Limit`, set both `stopPrice` and `limitPrice`, and omit `minBaseAssetAmount` |\n\nUse `toNano('65000')` for a price of 65,000. For attached SL/TP, reserve one query ID for the opening order plus one for each trigger. The SDK assigns the extra IDs consecutively. Limit orders open or increase a position; they do not reduce it.\n\n## Close a position\n\nThis prepares a close of **0.001 units of the base asset**. Use the position's direction and a new reserved `closeQueryId`:\n\n```typescript\nconst close = await prepareOrder({\n  smartAccount, market, signer,\n  queryId: closeQueryId,\n  createdAt: Math.floor(Date.now() / 1000) - 5,\n  order: {\n    type: OrderType.TakeProfit,\n    expiration: Math.floor(Date.now() / 1000) + 600,\n    direction: 0,\n    amount: toNano('0.001'),\n    triggerPrice: 0n,\n  },\n});\n```\n\nSave the result, then submit `close.request` with `api.placeOrder`. For a full close, use the current position size as `amount`.\n\n## Cancel an order\n\nUse the resting order's `orderHash`, either a hex hash or an ID starting with `@offchain:`:\n\n```typescript\nconst cancellation = await prepareCancel(smartAccount, orderHash, signer);\n```\n\nSave the target `orderHash` and the cancellation's hash and request before sending:\n\n```typescript\nawait api.cancelOrder(cancellation.request);\n```\n\nCancellation needs no new query ID. Check the target order's final status to confirm it was cancelled; a successful request alone is not confirmation.\n\n## Amounts and account setup\n\nV3 order amounts, position sizes, prices and leverage use **9 decimals**: `toNano('100')` means 100. Deposits and withdrawals use the token's own decimals: 6 for USDT, 9 for TON. Times use Unix seconds. Keep large values as `bigint` or strings.\n\nThe owner wallet handles deposits, withdrawals and signing keys. The SDK provides `getSmartAccountAddress`, `depositPayload`, `withdrawalPayload` and `keyPayload`; follow the [account examples](https://github.com/storm-trade/sdk-js/tree/main/examples/builders#readme) to send the wallet transactions.\n\n- [Query IDs, signing and errors](dev_concepts.md)\n- [API reference](/developers/overview)\n- [V2 wallet transactions](sdk_js_v2.md)\n- [SDK source](https://github.com/storm-trade/sdk-js) · [npm package](https://www.npmjs.com/package/@storm-trade/trading-sdk)\n","text":"🟨 JavaScript / TypeScript SDK Use the V3 SDK to place orders, manage positions and read Smart Account balances. Install The examples use Node.js 22 and SDK 1.1.0 : Connect First, fund the user's Smart Account and register a signing key. Get the market's vAMM address from markets. Replace the two addresses with your own. This URL is Mainnet . For testing, get matching API and contract addresses during builder onboarding. The examples below use three values from your application: signer : the registered key's 32 byte publicKey and a sign(hash) function that returns a 64 byte Ed25519 signature. It signs the cell hash directly. queryId : an unused ID reserved for this Smart Account. The SDK does not reserve IDs for you. minimumBaseAmount : the minimum base asset size you accept, based on your quote and slippage setting, with 9 decimals. For complete account and signer setup, use the runnable examples. Wallet transaction signatures and ton proof cannot replace the intent signer. Place a market order This opens a long position with 100 collateral and 3× leverage : Save prepared.hash , prepared.request and prepared.orderRequestHashes in your application before sending. Then submit: To earn builder fees, add your registered builder address to prepareOrder . See Builder Fees. Check the result accepted means the API received the order. Neither accepted nor done proves a fill. Confirm the result through account bundles, transactions and position state. If a request times out, check the saved hash before creating another order. The first order may already be accepted. The SDK does not retry automatically. Add SL/TP or use a limit price In the opening order above: Action Change Stop loss Set stopTriggerPrice to your stop price Take profit Set takeTriggerPrice to your target price Limit order Use OrderType.Limit , set limitPrice , and replace minBaseAssetAmount with stopPrice: 0n Stop market Use OrderType.Limit , set stopPrice , keep limitPrice: 0n , and omit minBaseAssetAmount Stop limit Use OrderType.Limit , set both stopPrice and limitPrice , and omit minBaseAssetAmount Use toNano('65000') for a price of 65,000. For attached SL/TP, reserve one query ID for the opening order plus one for each trigger. The SDK assigns the extra IDs consecutively. Limit orders open or increase a position; they do not reduce it. Close a position This prepares a close of 0.001 units of the base asset . Use the position's direction and a new reserved closeQueryId : Save the result, then submit close.request with api.placeOrder . For a full close, use the current position size as amount . Cancel an order Use the resting order's orderHash , either a hex hash or an ID starting with @offchain: : Save the target orderHash and the cancellation's hash and request before sending: Cancellation needs no new query ID. Check the target order's final status to confirm it was cancelled; a successful request alone is not confirmation. Amounts and account setup V3 order amounts, position sizes, prices and leverage use 9 decimals : toNano('100') means 100. Deposits and withdrawals use the token's own decimals: 6 for USDT, 9 for TON. Times use Unix seconds. Keep large values as bigint or strings. The owner wallet handles deposits, withdrawals and signing keys. The SDK provides getSmartAccountAddress , depositPayload , withdrawalPayload and keyPayload ; follow the account examples to send the wallet transactions. Query IDs, signing and errors API reference V2 wallet transactions SDK source · npm package"}