@tonconnect/sdk 3.3.1 → 3.4.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -0
- package/dist/tonconnect-sdk.min.js +1 -1
- package/dist/tonconnect-sdk.min.js.map +1 -1
- package/lib/cjs/index.cjs +1090 -201
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/esm/index.mjs +1085 -202
- package/lib/esm/index.mjs.map +1 -1
- package/lib/types/index.d.ts +336 -50
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -247,6 +247,16 @@ try {
|
|
|
247
247
|
}
|
|
248
248
|
```
|
|
249
249
|
|
|
250
|
+
You can pass a custom trace ID to track the transaction through your analytics:
|
|
251
|
+
|
|
252
|
+
```ts
|
|
253
|
+
const result = await connector.sendTransaction(transaction, {
|
|
254
|
+
traceId: '019a2a92-a884-7cfc-b1bc-caab18644b6f' // optional, UUIDv7 auto-generated if not provided
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
console.log(result.traceId); // use this ID to correlate with analytics events
|
|
258
|
+
```
|
|
259
|
+
|
|
250
260
|
## Sign data
|
|
251
261
|
|
|
252
262
|
Sign arbitrary data with the user's wallet. The wallet will display the data to the user for confirmation before signing.
|
|
@@ -289,6 +299,16 @@ try {
|
|
|
289
299
|
}
|
|
290
300
|
```
|
|
291
301
|
|
|
302
|
+
You can also pass a trace ID to correlate with analytics:
|
|
303
|
+
|
|
304
|
+
```ts
|
|
305
|
+
const result = await connector.signData(textData, {
|
|
306
|
+
traceId: '019a2a92-a884-7cfc-b1bc-caab18644b6f' // optional, UUIDv7 auto-generated if not provided
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
console.log(result.traceId); // use this ID to correlate with analytics events
|
|
310
|
+
```
|
|
311
|
+
|
|
292
312
|
#### Binary Format
|
|
293
313
|
|
|
294
314
|
Use for arbitrary binary data. The wallet shows a warning about unknown content.
|
|
@@ -410,6 +430,40 @@ connector.connect(
|
|
|
410
430
|
```
|
|
411
431
|
Note that you can use `tonProof` only with `connector.connect()` method. This feature is not available in `connector.restoreConnection()`.
|
|
412
432
|
|
|
433
|
+
### Network selection
|
|
434
|
+
|
|
435
|
+
You 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`.
|
|
436
|
+
|
|
437
|
+
```ts
|
|
438
|
+
import { CHAIN, WalletWrongNetworkError } from '@tonconnect/sdk';
|
|
439
|
+
|
|
440
|
+
const connector = new TonConnect();
|
|
441
|
+
|
|
442
|
+
// Set desired network before connecting, possible values is CHAIN.MAINNET ('-239'), CHAIN.TESTNET ('-3'), or any custom chainId string
|
|
443
|
+
connector.setConnectionNetwork(CHAIN.MAINNET);
|
|
444
|
+
|
|
445
|
+
// Or allow any network if needed (default behavior)
|
|
446
|
+
// connector.setConnectionNetwork(undefined);
|
|
447
|
+
|
|
448
|
+
// And connect wallet
|
|
449
|
+
connector.connect(walletConnectionSource);
|
|
450
|
+
|
|
451
|
+
// Handle network mismatch error
|
|
452
|
+
connector.onStatusChange(
|
|
453
|
+
wallet => { /* ... */ },
|
|
454
|
+
error => {
|
|
455
|
+
if (error instanceof WalletWrongNetworkError) {
|
|
456
|
+
console.error('Wrong network:', error.cause.expectedChainId, 'vs', error.cause.actualChainId);
|
|
457
|
+
// UI will display a user-friendly error message
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
);
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
**Important:**
|
|
464
|
+
- Network must be set before calling `connect()`. Attempting to change network while connected will throw an error.
|
|
465
|
+
- Network validation is also performed for `sendTransaction` and `signData` operations if a network was specified.
|
|
466
|
+
|
|
413
467
|
3. Read a signed result after user approves connection:
|
|
414
468
|
```ts
|
|
415
469
|
connector.onStatusChange(wallet => {
|