WalletConnect / walletconnect-monorepo

WalletConnect Monorepo
Apache License 2.0
1.46k stars 713 forks source link

Web3Wallet NodeJS crash when "Error: Unsupported chains. connect() optionalNamespaces" occur #3759

Closed truongezgg closed 1 year ago

truongezgg commented 1 year ago

My NodeJS Web3Wallet app crash when Error: Unsupported chains. connect() optionalNamespaces occur

If user provide invalid URI or Dapp provide invalid optionalNamespaces, expect WC just throw an "Error", not crash

How to fix it? Do you guys have any ideas on this issue?

SDK Version

Error

  1. I get WalletConnect URI connect from www.dexscreener.com
  2. Run await web3wallet.pair({ uri });
  3. An error occur and my NodeJS app crash. I have to run it again.

There are my code:

web3wallet.on('session_proposal', async proposal => {...})

await web3wallet.pair({ uri }); // This step success, no error
Error: Unsupported chains. connect() optionalNamespaces, chains must be defined as "namespace:chainId" e.g. "eip155:1": {...} in the namespace key OR as an array of CAIP-2 chainIds e.g. eip155: { chains: ["eip155:1", "eip155:5"] }
    at le.validateNamespaces (/path/to/my-app/node_modules/@walletconnect/sign-client/dist/index.cjs.js:1:22935)
    at le.isValidConnect (/path/to/my-app/node_modules/@walletconnect/sign-client/dist/index.cjs.js:1:22728)
    at le.onSessionProposeRequest (/path/to/my-app/node_modules/@walletconnect/sign-client/dist/index.cjs.js:1:15182)
    at le.processRequest (/path/to/my-app/node_modules/@walletconnect/sign-client/dist/index.cjs.js:1:13762)
    at le.processRequestsQueue (/path/to/my-app/node_modules/@walletconnect/sign-client/dist/index.cjs.js:1:13527)
    at le.onRelayEventRequest (/path/to/my-app/node_modules/@walletconnect/sign-client/dist/index.cjs.js:1:13128)
    at EventEmitter.<anonymous> (/path/to/my-app/node_modules/@walletconnect/sign-client/dist/index.cjs.js:1:28916)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
ganchoradkov commented 1 year ago

Hey @truongezgg, the error states that chains must be defined in your optionalNamespaces. Either as eip155:1 in the key, or in chains: string[] property