{"_id":"@alejandbel/ton-connect-sdk","name":"@alejandbel/ton-connect-sdk","dist-tags":{"latest":"3.4.1"},"versions":{"3.4.1":{"name":"@alejandbel/ton-connect-sdk","version":"3.4.1","repository":{"type":"git","url":"git+https://github.com/Alejandbel/ton-connect-sdk.git"},"homepage":"https://github.com/Alejandbel/ton-connect-sdk/tree/main/packages/sdk","bugs":{"url":"https://github.com/Alejandbel/ton-connect-sdk/issues"},"keywords":["TON","Wallet","ton-connect","Connect","Tonkeeper","sdk"],"author":{"name":"tonconnect"},"license":"Apache-2.0","dependencies":{"@tonconnect/isomorphic-eventsource":"npm:@alejandbel/ton-connect-isomorphic-eventsource@0.0.2","@tonconnect/protocol":"npm:@alejandbel/ton-connect-protocol@2.4.0","@tonconnect/isomorphic-fetch":"npm:@alejandbel/ton-connect-isomorphic-fetch@0.0.3"},"main":"./lib/cjs/index.cjs","module":"./lib/esm/index.mjs","types":"./lib/types/index.d.ts","exports":{".":{"types":"./lib/types/index.d.ts","require":"./lib/cjs/index.cjs","import":"./lib/esm/index.mjs","default":"./lib/cjs/index.cjs"}},"devDependencies":{"@rollup/plugin-replace":"6.0.2","@rollup/plugin-typescript":"^12.1.4","@types/node":"^24.2.0","@vitest/coverage-istanbul":"3.2.4","rollup":"^4.46.2","ts-loader":"^9.4.1","ts-patch":"^3.3.0","typescript-transform-paths":"^3.3.1","vite":"^7.0.6","vite-tsconfig-paths":"^5.1.4","vitest":"^3.2.4","vitest-fetch-mock":"^0.4.5","webpack":"^5.75.0","webpack-cli":"^5.0.0"},"typedoc":{"entryPoint":"./src/index.ts"},"scripts":{"build":"rimraf types-dist && rimraf lib && rollup -c rollup.config.mjs && tspc --project tsconfig.declarations.json && api-extractor run && rimraf types-dist && rimraf dist && webpack --config webpack.config.js","test":"vitest run"},"_id":"@alejandbel/ton-connect-sdk@3.4.1","description":"Use it to connect your app to TON wallets via TonConnect protocol.  You can find more details and the protocol specification in the [docs](https://docs.ton.org/develop/dapps/ton-connect/overview). See the example of sdk usage [here](https://github.com/ton","_integrity":"sha512-wX30goiLAiOp04TGJT1Pcpl3GbMlm2Bz0SqA6sFvUKAdSXAhMNMzyhTMJYEwGyhKyMwgyeJnnbF2ijj4WB47UA==","_resolved":"/private/var/folders/h9/wfnrk3496fx8kcbxgcpnmwsm0000gn/T/d02acca215bdb913718e48387f721117/alejandbel-ton-connect-sdk-3.4.1.tgz","_from":"file:alejandbel-ton-connect-sdk-3.4.1.tgz","_nodeVersion":"24.11.0","_npmVersion":"11.6.1","dist":{"integrity":"sha512-wX30goiLAiOp04TGJT1Pcpl3GbMlm2Bz0SqA6sFvUKAdSXAhMNMzyhTMJYEwGyhKyMwgyeJnnbF2ijj4WB47UA==","shasum":"6ca921237c967f1ba3517194e424e964c4134ad8","tarball":"https://registry.npmjs.org/@alejandbel/ton-connect-sdk/-/ton-connect-sdk-3.4.1.tgz","fileCount":10,"unpackedSize":1751350,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDSxKMB8wZdkLykCc41KqAfLaBJvuUK+2DKcD7ACx6bVQIhAPivc+L04F2nNqcOL4Gm5GLlDaLfXSnVE1rG+g471+8q"}]},"_npmUser":{"name":"a-bahdanau","email":"bogdanov28c@gmail.com"},"directories":{},"maintainers":[{"name":"a-bahdanau","email":"bogdanov28c@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/ton-connect-sdk_3.4.1_1773234449735_0.30647195896467294"},"_hasShrinkwrap":false}},"time":{"created":"2026-03-11T13:07:29.631Z","3.4.1":"2026-03-11T13:07:29.951Z","modified":"2026-03-11T13:07:30.191Z"},"maintainers":[{"name":"a-bahdanau","email":"bogdanov28c@gmail.com"}],"description":"Use it to connect your app to TON wallets via TonConnect protocol.  You can find more details and the protocol specification in the [docs](https://docs.ton.org/develop/dapps/ton-connect/overview). See the example of sdk usage [here](https://github.com/ton","homepage":"https://github.com/Alejandbel/ton-connect-sdk/tree/main/packages/sdk","keywords":["TON","Wallet","ton-connect","Connect","Tonkeeper","sdk"],"repository":{"type":"git","url":"git+https://github.com/Alejandbel/ton-connect-sdk.git"},"author":{"name":"tonconnect"},"bugs":{"url":"https://github.com/Alejandbel/ton-connect-sdk/issues"},"license":"Apache-2.0","readme":"# TON Connect SDK\n\nUse it to connect your app to TON wallets via TonConnect protocol. \nYou can find more details and the protocol specification in the [docs](https://docs.ton.org/develop/dapps/ton-connect/overview).\nSee the example of sdk usage [here](https://github.com/ton-connect/demo-dapp).\n\n[Latest API documentation](https://ton-connect.github.io/sdk/modules/_tonconnect_sdk.html)\n\n# Getting started\n## Installation with cdn\nAdd the script to your HTML file:\n```html\n<script src=\"https://unpkg.com/@tonconnect/sdk@latest/dist/tonconnect-sdk.min.js\"></script>\n```\n\nℹ️ If you don't want auto-update the library, pass concrete version instead of `latest`, e.g. \n```html\n<script src=\"https://unpkg.com/@tonconnect/sdk@0.0.34/dist/tonconnect-sdk.min.js\"></script>\n```\n\nYou can find `TonConnect` in global variable `TonConnectSDK`, e.g.\n```html\n<script>\n    const connector = new TonConnectSDK.TonConnect();\n</script>\n```\n\n## Installation with npm\n`npm i @tonconnect/sdk`\n\n# Usage\n## Init connector and call restoreConnection. If user connected his wallet before, connector will restore the connection\n\n```ts\nimport TonConnect from '@tonconnect/sdk';\n\nconst connector = new TonConnect();\n\nconnector.restoreConnection();\n```\n\n## Add the tonconnect-manifest\nApp needs to have its manifest to pass meta information to the wallet. Manifest is a JSON file named as `tonconnect-manifest.json` following format:\n\n```json\n{\n  \"url\": \"<app-url>\",                        // required\n  \"name\": \"<app-name>\",                      // required\n  \"iconUrl\": \"<app-icon-url>\",               // required\n  \"termsOfUseUrl\": \"<terms-of-use-url>\",     // optional\n  \"privacyPolicyUrl\": \"<privacy-policy-url>\" // optional\n}\n```\n\nBest practice is to place the manifest in the root of your app, e.g. `https://myapp.com/tonconnect-manifest.json`. It allows the wallet to handle your app better and improve the UX connected to your app.\nMake sure that manifest is available to GET by its URL.\n\n[See details](https://docs.ton.org/develop/dapps/ton-connect/protocol/requests-responses#app-manifest)\n\nIf your manifest placed not in the root of your app, you can specify its path:\n```ts\nconst connector = new TonConnect({\n    manifestUrl: 'https://myApp.com/assets/tonconnect-manifest.json'\n});\n```\n\n## Analytics\n\nYou can configure analytics collection when creating the connector:\n\n```ts\nconst connector = new TonConnect({\n    manifestUrl: 'https://myApp.com/tonconnect-manifest.json',\n    analytics: { mode: 'off' } // or 'telemetry' (default), 'full'\n});\n```\n\n**Analytics modes:**\n\n| Mode                    | Description                                                |\n|-------------------------|------------------------------------------------------------|\n| **off**                 | Analytics turned off. No events are collected or sent.     |\n| **telemetry** (default) | Analytics used for technical research and issue debugging. |\n| **full**                | Full analytics events.                                     |\n\n## Subscribe to the connection status changes\n```js\nconst unsubscribe = connector.onStatusChange(\n    walletInfo => {\n        // update state/reactive variables to show updates in the ui\n    } \n);\n\n// call `unsubscribe()` later to save resources when you don't need to listen for updates anymore.\n```\n\n## Fetch wallets list\n\nTonConnect is build to support different wallets. You can fetch all supported wallets list and show a custom wallet selection dialog for user.\n\n```ts\nconst walletsList = await connector.getWallets();\n\n/* walletsList is \n{\n    name: string;\n    imageUrl: string;\n    tondns?: string;\n    aboutUrl: string;\n    universalLink?: string;\n    deepLink?: string;\n    bridgeUrl?: string;\n    jsBridgeKey?: string;\n    injected?: boolean; // true if this wallet is injected to the webpage\n    embedded?: boolean; // true if the dapp is opened inside this wallet's browser\n}[] \n */\n```\n\nYou also can get wallets list using `getWallets` static method:\n```ts\nconst walletsList = await TonConnect.getWallets();\n```\n\n### WalletInfo utils and type guards\nFollowing type guards might be helpful for WalletInfos manipulations:\n\n```ts\nimport {\n    isWalletInfoCurrentlyEmbedded,\n    isWalletInfoInjectable,\n    isWalletInfoCurrentlyInjected,\n    isWalletInfoRemote,\n    WalletInfo\n} from '@tonconnect/sdk';\n\n/* Use for filtration */\nconst remoteConnectionWalletInfos = walletInfoList.filter(isWalletInfoRemote);\n\n// all wallets that supports injecteble connection (EVEN THOSE THAT ARE NOT INJECTED TO THE CURRENT PAGE) \nconst injectableConnectionWalletInfos = walletInfoList.filter(isWalletInfoInjectable);\n\n// wallets that are injected to the current webpage \nconst currentlyInjectedWalletInfos = walletInfoList.filter(isWalletInfoCurrentlyInjected);\nconst embeddedWalletInfo = walletInfoList.find(isWalletInfoCurrentlyEmbedded);\n\n    \n/* or use as type guard */\nif (isWalletInfoRemote(walletInfo)) {\n    connector.connect({\n        universalLink: walletInfo.universalLink,\n        bridgeUrl: walletInfo.bridgeUrl\n    });\n    return;\n}\n\nif (isWalletInfoCurrentlyInjected(walletInfo)) {\n    connector.connect({\n        jsBridgeKey: walletInfo.jsBridgeKey\n    });\n    return;\n}\n```\n\n## Initialize a wallet connection when user clicks to 'connect' button in your app\n### Initialize a remote wallet connection via universal link \n\n```ts\n// Should correspond to the wallet that user selects\nconst walletConnectionSource = {\n    universalLink: 'https://app.tonkeeper.com/ton-connect',\n    bridgeUrl: 'https://bridge.tonapi.io/bridge'\n}\n\nconst universalLink = connector.connect(walletConnectionSource);\n```\n\nThen you have to show this link to user as QR code, or use it as a deeplink. You will receive an update in `connector.onStatusChange` when user approves connection in the wallet.\n\n### Initialize injected wallet connection\n```ts\n// Should correspond to the wallet that user selects\nconst walletConnectionSource = {\n    jsBridgeKey: 'tonkeeper'\n}\n\nconnector.connect(walletConnectionSource);\n```\n\nYou will receive an update in `connector.onStatusChange` when user approves connection in the wallet.\n\n### Create unified link\nYou can create the unified link that could be accepted by any wallet. To do that you should pass an array of http-wallet-connection-sources:\n\nIf several wallets have same bridge url, you can pass this url only once.\n```ts\nconst sources = [\n    {\n        bridgeUrl: 'https://bridge.tonapi.io/bridge' // Tonkeeper\n    },\n    {\n        bridgeUrl: 'https://<OTHER_WALLET_BRIDGE>' // Tonkeeper\n    }\n];\n\nconnector.connect(sources);\n```\n\n### Detect embedded wallet\nIt is recommended not to show a QR code modal if the app is opened inside a wallet's browser. \nYou should detect working environment of the app and show appropriate UI.\nCheck `embedded` property in elements of the wallets list to detect if the app is opened inside a wallet.\n\n```ts\nimport { isWalletInfoCurrentlyEmbedded, WalletInfoCurrentlyEmbedded } from '@tonconnect/sdk';\n\n// \"connect button\" click handler.\n// Execute this before show wallet selection modal.\n\nconst walletsList = await connector.getWallets(); // or use `walletsList` fetched before  \n\nconst embeddedWallet = walletsList.find(isWalletInfoCurrentlyEmbedded) as WalletInfoCurrentlyEmbedded;\n\nif (embeddedWallet) {\n    connector.connect({ jsBridgeKey: embeddedWallet.jsBridgeKey });\n    return;\n}\n\n// else show modal and ask user to select a wallet\n```\n\n## Send transaction\n```ts\nif (!connector.connected) {\n    alert('Please connect wallet to send the transaction!');\n}\n\nconst transaction = {\n    validUntil: Math.floor(Date.now() / 1000) + 60, // 60 sec\n    messages: [\n        {\n            address: \"EQBBJBB3HagsujBqVfqeDUPJ0kXjgTPLWPFFffuNXNiJL0aA\",\n            amount: \"20000000\",\n         // stateInit: \"base64bocblahblahblah==\" // just for instance. Replace with your transaction initState or remove\n        },\n        {\n            address: \"EQDmnxDMhId6v1Ofg_h5KR5coWlFG6e86Ro3pc7Tq4CA0-Jn\",\n            amount: \"60000000\",\n         // payload: \"base64bocblahblahblah==\" // just for instance. Replace with your transaction payload or remove\n        }\n    ]\n}\n\ntry {\n    const result = await connector.sendTransaction(transaction);\n    \n    // you can use signed boc to find the transaction \n    const someTxData = await myAppExplorerService.getTransaction(result.boc);\n    alert('Transaction was sent successfully', someTxData);\n} catch (e) {\n    if (e instanceof UserRejectedError) {\n        alert('You rejected the transaction. Please confirm it to send to the blockchain');\n    } else {\n        alert('Unknown error happened', e);\n    }\n}\n```\n\nYou can pass a custom trace ID to track the transaction through your analytics:\n\n```ts\nconst result = await connector.sendTransaction(transaction, {\n    traceId: '019a2a92-a884-7cfc-b1bc-caab18644b6f' // optional, UUIDv7 auto-generated if not provided\n});\n\nconsole.log(result.traceId); // use this ID to correlate with analytics events\n```\n\n## Sign data\n\nSign arbitrary data with the user's wallet. The wallet will display the data to the user for confirmation before signing.\n\n### Data Types\n\nYou can sign three types of data. Choose the right format based on your use case:\n\n- **Text** - Use for human-readable text that users should see and understand\n- **Cell** - Use for TON Blockchain data that should be used in smart contracts (wallet may show unknown content warning)  \n- **Binary** - For other arbitrary data (least preferred due to security warnings)\n\n#### Text Format\n\nUse when you need to sign human-readable text. The wallet displays the text to the user.\n\n**Parameters:**\n- `type` (string, required): Must be `\"text\"`\n- `text` (string, required): UTF-8 text to sign\n- `network` (string, optional): `\"-239\"` for mainnet, `\"-3\"` for testnet\n- `from` (string, optional): Signer address in raw format `\"0:<hex>\"`\n\n```ts\nconst textData = {\n    type: \"text\",\n    text: \"Confirm new 2fa number:\\n+1 234 567 8901\",\n    network: \"-239\", // MAINNET = '-239', TESTNET = '-3'\n    from: \"0:348bcf827469c5fc38541c77fdd91d4e347eac200f6f2d9fd62dc08885f0415f\"\n};\n\ntry {\n    const result = await connector.signData(textData);\n    console.log('Signed:', result);\n} catch (e) {\n    if (e instanceof UserRejectedError) {\n        console.log('User rejected signing');\n    } else {\n        console.error('Error:', e);\n    }\n}\n```\n\nYou can also pass a trace ID to correlate with analytics:\n\n```ts\nconst result = await connector.signData(textData, {\n    traceId: '019a2a92-a884-7cfc-b1bc-caab18644b6f' // optional, UUIDv7 auto-generated if not provided\n});\n\nconsole.log(result.traceId); // use this ID to correlate with analytics events\n```\n\n#### Binary Format\n\nUse for arbitrary binary data. The wallet shows a warning about unknown content.\n\n**Parameters:**\n- `type` (string, required): Must be `\"binary\"`\n- `bytes` (string, required): Base64 encoded binary data (not url-safe)\n- `network` (string, optional): `\"-239\"` for mainnet, `\"-3\"` for testnet\n- `from` (string, optional): Signer address in raw format `\"0:<hex>\"`\n\n```ts\nconst binaryData = {\n    type: \"binary\",\n    bytes: \"1Z/SGh+3HFMKlVHSkN91DpcCzT4C5jzHT3sA/24C5A==\",\n    network: \"-239\", // MAINNET = '-239', TESTNET = '-3'\n    from: \"0:348bcf827469c5fc38541c77fdd91d4e347eac200f6f2d9fd62dc08885f0415f\"\n};\n\ntry {\n    const result = await connector.signData(binaryData);\n    console.log('Signed:', result);\n} catch (e) {\n    if (e instanceof UserRejectedError) {\n        console.log('User rejected signing');\n    } else {\n        console.error('Error:', e);\n    }\n}\n```\n\n#### Cell Format\n\nUse for TON Blockchain data with TL-B schema. The wallet can parse and display the content if the schema is valid.\n\n**Parameters:**\n- `type` (string, required): Must be `\"cell\"`\n- `schema` (string, required): TL-B schema of the cell payload\n- `cell` (string, required): Base64 encoded BoC (not url-safe) with single-root cell\n- `network` (string, optional): `\"-239\"` for mainnet, `\"-3\"` for testnet\n- `from` (string, optional): Signer address in raw format `\"0:<hex>\"`\n\n```ts\nconst cellData = {\n    type: \"cell\",\n    schema: \"transfer#0f8a7ea5 query_id:uint64 amount:(VarUInteger 16) destination:MsgAddress response_destination:MsgAddress custom_payload:(Maybe ^Cell) forward_ton_amount:(VarUInteger 16) forward_payload:(Either Cell ^Cell) = InternalMsgBody;\",\n    cell: \"te6ccgEBAQEAVwAAqg+KfqVUbeTvKqB4h0AcnDgIAZucsOi6TLrfP6FcuPKEeTI6oB3fF/NBjyqtdov/KtutACCLqvfmyV9kH+Pyo5lcsrJzJDzjBJK6fd+ZnbFQe4+XggI=\",\n    network: \"-239\", // MAINNET = '-239', TESTNET = '-3'\n    from: \"0:348bcf827469c5fc38541c77fdd91d4e347eac200f6f2d9fd62dc08885f0415f\"\n};\n\ntry {\n    const result = await connector.signData(cellData);\n    console.log('Signed:', result);\n} catch (e) {\n    if (e instanceof UserRejectedError) {\n        console.log('User rejected signing');\n    } else {\n        console.error('Error:', e);\n    }\n}\n```\n\n### Response\n\nAll signData calls return the same response structure:\n\n```ts\ninterface SignDataResult {\n    signature: string; // Base64 encoded signature\n    address: string;   // Wallet address in raw format\n    timestamp: number; // UNIX timestamp in seconds (UTC)\n    domain: string;    // App domain name \n    payload: object;   // Original payload from the request\n}\n```\n\n### Signature Verification\n\nAfter receiving the signed data, you need to verify the signature to ensure it's authentic and was signed by the claimed wallet address.\n\n**For backend verification:** See [TypeScript verification example](https://github.com/ton-connect/demo-dapp-with-react-ui/blob/master/src/server/services/sign-data-service.ts#L32-L109) showing how to verify signatures on your server.\n\n**For smart contract verification:** See [FunC verification example](https://github.com/p0lunin/sign-data-contract-verify-example/blob/master/contracts/sign_data_example.fc) showing how to verify signatures in TON smart contracts.\n\n**For complete technical details:** See the [Sign Data specification](https://github.com/ton-blockchain/ton-connect/blob/main/requests-responses.md#sign-data) for full signature verification requirements.\n\n## Disconnect wallet\nNote that if you want to change connected wallet, you should disconnect current one firstly. Also make sure that you've waited for `restoreConnection()` promise resolved before call `disconnect()`;\n\n```ts\nif (connector.connected) {\n    await connector.disconnect();\n}\n```\n# Utils\n\n## Convert address to user-friendly format\nUse `toUserFriendlyAddress` function to convert raw-address to the user-friendly format. You can pass `true` as a second\nparameter to make it 'testnet only' (disabled by default).\n\n\n```ts\nimport { toUserFriendlyAddress } from '@tonconnect/sdk';\n\nconst rawAddress = connector.wallet.account.address; // like '0:abcdef123456789...'\nconst bouncableUserFriendlyAddress = toUserFriendlyAddress(rawAddress);\nconst testnetOnlyBouncableUserFriendlyAddress = toUserFriendlyAddress(rawAddress, true);\n```\n\n# Backend authorization\nTo authorize user in your backend with TonConnect you can use following schema:\n1. Fetch auth payload from your backend. It might be any random value. Backend must save information that this payload was sent to the client to check payload correctness later.\n2. Connect to the wallet when user clicks to the connection button:\n```ts\nconnector.connect(\n  walletConnectionSource, \n  { tonProof: \"<your-fetched-payload>\" }\n);\n```\nNote that you can use `tonProof` only with `connector.connect()` method. This feature is not available in `connector.restoreConnection()`.\n\n### Network selection\n\nYou can specify the desired network before connecting to a wallet using the `setConnectionNetwork()` method. If the wallet connects to a different network, the connection will be aborted with a `WalletWrongNetworkError`.\n\n```ts\nimport { CHAIN, WalletWrongNetworkError } from '@tonconnect/sdk';\n\nconst connector = new TonConnect();\n\n// Set desired network before connecting, possible values is CHAIN.MAINNET ('-239'), CHAIN.TESTNET ('-3'), or any custom chainId string\nconnector.setConnectionNetwork(CHAIN.MAINNET); \n\n// Or allow any network if needed (default behavior)\n// connector.setConnectionNetwork(undefined);\n\n// And connect wallet\nconnector.connect(walletConnectionSource);\n\n// Handle network mismatch error\nconnector.onStatusChange(\n  wallet => { /* ... */ },\n  error => {\n    if (error instanceof WalletWrongNetworkError) {\n      console.error('Wrong network:', error.cause.expectedChainId, 'vs', error.cause.actualChainId);\n      // UI will display a user-friendly error message\n    }\n  }\n);\n```\n\n**Important:** \n- Network must be set before calling `connect()`. Attempting to change network while connected will throw an error.\n- Network validation is also performed for `sendTransaction` and `signData` operations if a network was specified.\n\n3. Read a signed result after user approves connection:\n```ts\nconnector.onStatusChange(wallet => {\n    if (!wallet) {\n        return;\n    }\n\n    const tonProof = wallet.connectItems?.tonProof;\n\n    if (tonProof) {\n        if ('proof' in tonProof) {\n            // send proof to your backend\n            // e.g. myBackendCheckProof(tonProof.proof, wallet.account);\n            return;\n        }\n\n        console.error(tonProof.error);\n    }\n});\n```\n4. Send proof and user's account data to your backend. Backend should check the proof correctness and check that payload inside the proof was generated before. After all checks backend should return an auth token to the client. Notice that `Account` contains the `walletStateInit` property which can be helpful for your backend to get user's public key if user's wallet contract doesn't support corresponding get method.\n5. Client saves the auth token in the `localStorage` and use it to access to auth-required endpoints. Client should delete the token when user disconnects the wallet.\n\n[See an example of a dapp using backend authorization](https://github.com/ton-connect/demo-dapp-with-backend). \n\n[See an example of the dapp backend](https://github.com/ton-connect/demo-dapp-backend). \n\n\n# Use with NodeJS\nYou can use the SDK in frontend apps and in backend apps created with NodeJS. \n\n## Installation\n`npm i @tonconnect/sdk`\n\n## Init connector\nWhen you use the SDK in backend, you have to pass `manifestUrl` and `IStorage` implementation to the TonConnect constructor.\n\n[See more about the manifest](##add-the-tonconnect-manifest).\n\n```ts\nimport TonConnect from '@tonconnect/sdk';\n\nconst storage: IStorage = <your implementation of the IStorage>\n\nconst connector = new TonConnect({ manifestUrl, storage });\n```\n\nYour storage should implement following interface:\n```ts\nexport interface IStorage {\n    setItem(key: string, value: string): Promise<void>;\n    getItem(key: string): Promise<string | null>;\n    removeItem(key: string): Promise<void>;\n}\n```\n\n[See details about IStorage in the API documentation](https://ton-connect.github.io/sdk/interfaces/_tonconnect_sdk.IStorage.html).\n\nOther steps are the same as for browser apps.\n\n## Pause and unpause connection\nYou can pause and unpause HTTP connection using `tonConnect.pauseConnection()` and `tonConnect.unPauseConnection()` to save your server resources.   \n\n```ts\nmyTelegramBot.userIsOffline(user => {\n    const connector = myFunctionGetConnectorByUser(user);\n    connector.pauseConnection();  \n})\n\nmyTelegramBot.userIsOnline(user => {\n    const connector = myFunctionGetConnectorByUser(user);\n    connector.unPauseConnection();\n})\n```\n\n# Tracking\n\n## Track events\n\nTracker for TonConnect user actions, such as transaction signing, connection, etc.\n\nList of events:\n* `connection-started`: when a user starts connecting a wallet.\n* `connection-completed`: when a user successfully connected a wallet.\n* `connection-error`: when a user cancels a connection or there is an error during the connection process.\n* `connection-restoring-started`: when the dApp starts restoring a connection.\n* `connection-restoring-completed`: when the dApp successfully restores a connection.\n* `connection-restoring-error`: when the dApp fails to restore a connection.\n* `disconnection`: when a user starts disconnecting a wallet.\n* `transaction-sent-for-signature`: when a user sends a transaction for signature.\n* `transaction-signed`: when a user successfully signs a transaction.\n* `transaction-signing-failed`: when a user cancels transaction signing or there is an error during the signing process.\n* `sign-data-request-initiated`: when a user initiates a request to sign data.\n* `sign-data-request-completed`: when a user successfully signs data.\n* `sign-data-request-failed`: when a user cancels data signing or there is an error during the signing process.\n\nIf you want to track user actions, you can subscribe to the window events with prefix `ton-connect-`:\n\n```typescript\nwindow.addEventListener('ton-connect-transaction-sent-for-signature', (event) => {\n    console.log('Transaction init', event.detail);\n});\n```\n\n## Use custom event dispatcher\n\nYou can use your custom event dispatcher to track user actions. To do this, you need to pass the `eventDispatcher` to the TonConnect constructor:\n\n```typescript\nimport {TonConnect, EventDispatcher, SdkActionEvent} from '@tonconnect/sdk';\n\nclass CustomEventDispatcher implements EventDispatcher<SdkActionEvent> {\n    public async dispatchEvent(\n      eventName: string, \n      eventDetails: SdkActionEvent\n    ): Promise<void> {\n        console.log(`Event: ${eventName}, details:`, eventDetails);\n    }\n}\n\nconst eventDispatcher = new CustomEventDispatcher();\n\nconst connector = new TonConnect({ eventDispatcher });\n```\n\n\n# Troubleshooting\n\n## Warning about 'encoding' module in Next.js\n\nIf you are using Next.js and see a warning similar to the following:\n\n```\n ⚠ ./node_modules/node-fetch/lib/index.js\nModule not found: Can't resolve 'encoding' in '.../node_modules/node-fetch/lib'\n\nImport trace for requested module:\n./node_modules/node-fetch/lib/index.js\n./node_modules/@tonconnect/isomorphic-fetch/index.mjs\n./node_modules/@tonconnect/sdk/lib/esm/index.mjs\n```\n\nPlease note that this is just a warning and should not affect the functionality of your application. If you wish to suppress the warning, you have two options:\n\n1. (Recommended) Wait for us to remove the dependency on `@tonconnect/isomorphic-fetch` in future releases. This dependency will be removed when we drop support for Node.js versions below 18.\n\n2. (Optional) Install the `encoding` package, to resolve the warning:\n```shell\nnpm install encoding\n```\n","readmeFilename":"README.md","_rev":"1-bb3b8d9d5ec704162037a38f631bf696"}