argentlabs / argent-x

ArgentX browser extension for StarkNet - made with ❤️ by Argent
https://github.com/argentlabs/argent-x
Other
625 stars 276 forks source link

Timeout when sending wallet_switchStarknetChain request #1615

Closed florian-bellotti closed 1 year ago

florian-bellotti commented 1 year ago

I could not succeed to configure the wallet_switchStarknetChain request. I always receive a Error: Timeout error.

Here is a sample of code i am using. This code is triggered just after the connection to a ArgentX account.

    getStarknet() // from get-starknet
      .getAvailableWallets()
      .then((wallets) => {
        wallets
          .filter((wallet) => wallet.id === 'argentX')[0]
          .request({
            type: 'wallet_switchStarknetChain',
            params: { chainId: constants.StarknetChainId.TESTNET2 },
          });
      });

I think that the error is triggered here, but I do not understand why.

requestMessageHandlers.ts

  const req = await Promise.race([
    waitForMessage("REQUEST_ADD_CUSTOM_NETWORK_RES", 1000),
    waitForMessage("REQUEST_ADD_CUSTOM_NETWORK_REJ", 1000),
  ])
dhruvkelawala commented 1 year ago

The params is incorrect. It expects chainId to be one of SN_MAIN, SN_GOERLI or SN_GOERLI2. So your code will change to



   getStarknet() // from get-starknet
      .getAvailableWallets()
      .then((wallets) => {
        wallets
          .filter((wallet) => wallet.id === 'argentX')[0]
          .request({
            type: 'wallet_switchStarknetChain',
            params: { chainId: 'SN_GOERLI2' },
          });
      });```

      Note: constants.StarknetChainId.TESTNET2 = `0x534e5f474f45524c4932`
dhruvkelawala commented 1 year ago

Added a better solution. But will be available in next release. With this PR, you can continue using constants.StarknetChainId.TESTNET2

pei-zklend commented 1 year ago

Just wanted to follow up on this, currently I am also having a timed out error when running wallet_switchStarknetChain request.

I am running

import { encodeShortString } from "starknet/dist/utils/shortString";

.request({
          type: "wallet_switchStarknetChain",
          params: {
            chainId: encodeShortString("SN_MAIN"),
          },
        })

to switch to the mainnet network but seems to be having issues with mainnet only. Any idea why?