Skip to content

connectedWallet.provider.request({ method: 'eth_chainId' }) always returns 1 when dealing with MetaMask browser extension #2384

@BabyBonComputer

Description

@BabyBonComputer

Current Behavior

My code:

  async function connectWeb3AccountWithSigningIn() {
    try {
      const wallets = await connect()
      const connectedWallet = wallets?.[0]
      const address = getAddress(connectedWallet.accounts[0].address)
      const provider = connectedWallet.provider
      const chainId = parseInt(await connectedWallet.provider.request({ method: 'eth_chainId' }), 16)

      const throughWallsUrl = process.env.NEXT_PUBLIC_THROUGH_WALLS_MAIN_PAGE_URL
      const throughWallsDomain = process.env.NEXT_PUBLIC_THROUGH_WALLS_DOMAIN

      const message = new SiweMessage({
        domain: throughWallsDomain,
        address: address,
        statement: 'Verify your wallet ownership to use our platform.',
        uri: throughWallsUrl,
        version: '1',
        chainId: chainId,
        nonce: 'k2b5z3f9q'
      });
      const messageToSign = message.prepareMessage();

      const signature = await provider.request({
        method: 'personal_sign',
        params: [messageToSign, address]
      });

    } finally {
      setUserMenuOpen(false)
    }
  }

  const web3Onboard = Onboard({
  wallets: [injected],
  chains: [
    {
      id: '0x1',
      token: 'ETH',
      label: 'Ethereum Mainnet',
      rpcUrl: ETH_RPC
    }
  ],
  appMetadata: {
    name: 'throughwalls',
    icon: 'logo_with_background.jpeg',
    description: 'Add your NFTs to images.',
    recommendedInjectedWallets: [
      { name: 'MetaMask', url: 'https://metamask.io' }
    ]
  },
  accountCenter: {
    desktop: {
      enabled: false,
    },
    mobile: {
      enabled: false,
    }
  },
})

I have two browser extansions: MetaMask and coinbase wallet. I select arbitrum network in two wallets. When i choose coinbase wallet, connectedWallet.provider.request({ method: 'eth_chainId' }) returns 42161, but when i choose MetaMask wallet this method always returns 1. Why ?

Expected Behavior

No response

Steps To Reproduce

No response

What package is effected by this issue?

@web3-onboard/core

Is this a build or a runtime issue?

Runtime

Package Version

2.24.1

Node Version

No response

What browsers are you seeing the problem on?

Chrome, Firefox

Relevant log output

Anything else?

No response

Sanity Check

  • If this is a build issue, I have included my build config. If this is a runtime issue, I have included reproduction steps and/or a Minimal, Reproducible Example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions