@tonconnect/sdk 3.4.0-beta.0 → 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 CHANGED
@@ -430,6 +430,40 @@ connector.connect(
430
430
  ```
431
431
  Note that you can use `tonProof` only with `connector.connect()` method. This feature is not available in `connector.restoreConnection()`.
432
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
+
433
467
  3. Read a signed result after user approves connection:
434
468
  ```ts
435
469
  connector.onStatusChange(wallet => {