@earthworm/wallet-sdk 0.2.2 → 0.2.5

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
@@ -16,7 +16,7 @@ import {
16
16
  getWalletSdkConfig,
17
17
  walletEvents,
18
18
  setWalletEventProvider,
19
- ensureTargetNetwork,
19
+ switchToConfiguredNetwork,
20
20
  requestWallet,
21
21
  resolveMetaMaskInjectedProvider,
22
22
  isEthereumProvider,
@@ -26,10 +26,12 @@ import {
26
26
  } from "@earthworm/wallet-sdk";
27
27
 
28
28
  initWalletSdk({
29
- isMainnet: true, // Set to true for mainnet, false for testnet
30
- contract: { address: "0x...", abi: [] },
29
+ usdt: { address: "0x55d398326f99059fF775485246999027B3197955" },
31
30
  });
32
31
 
32
+ // Optional: switch chain after connect
33
+ await connectWallet(provider, { chainId: "0x38" });
34
+
33
35
  // Detect installed wallets
34
36
  if (isEthereumProvider()) {
35
37
  console.log("MetaMask is available");
@@ -50,28 +52,23 @@ if (isTronLinkProvider()) {
50
52
  const provider = resolveMetaMaskInjectedProvider();
51
53
  setWalletEventProvider(provider ?? null);
52
54
 
53
- walletEvents.on("accountsChanged", (accounts) => {
54
- console.log(accounts);
55
+ walletEvents.on("accountsChanged", (wallet, event) => {
56
+ console.log(wallet, event.payload); // account addresses
57
+ });
58
+
59
+ walletEvents.on("chainChanged", (wallet, event) => {
60
+ console.log("Network changed:", wallet, event.payload); // hex chainId, e.g. "0x38"
55
61
  });
56
62
 
57
- walletEvents.on("chainChanged", (chainId) => {
58
- console.log("Network changed:", chainId); // hex chainId, e.g. "0x38"
63
+ walletEvents.on("networkSwitched", (wallet, event) => {
64
+ console.log(wallet, event.payload); // { chainId, previousChainId, switched }
59
65
  });
60
66
 
61
- async function switchToConfiguredNetwork() {
67
+ async function switchWalletToBscMainnet() {
62
68
  const provider = resolveMetaMaskInjectedProvider();
63
69
  if (!provider) return;
64
70
 
65
- const { chainId, chain } = getWalletSdkConfig();
66
-
67
- await ensureTargetNetwork({
68
- targetChainId: chainId,
69
- getCurrentChainId: () => requestWallet(provider, "eth_chainId") as Promise<string>,
70
- switchChain: (chainId) =>
71
- requestWallet(provider, "wallet_switchEthereumChain", [{ chainId }]),
72
- addChain: (chainParams) =>
73
- requestWallet(provider, "wallet_addEthereumChain", [chainParams]),
74
- chainParams: chain,
75
- });
71
+ setWalletEventProvider(provider);
72
+ await switchToConfiguredNetwork("0x38");
76
73
  }
77
74
  ```
@@ -0,0 +1,2 @@
1
+ export { applyWalletAccountsChangedEffect, applyWalletDisconnectEffect } from './chunk-HLZ3QZTH.js';
2
+ import './chunk-F7UNIZSN.js';