Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@walletconnect/ethereum-provider] accounts array is not updated after switching the chain #5706

Open
mahnunchik opened this issue Mar 14, 2025 · 2 comments
Labels
type: bug Something isn't working

Comments

@mahnunchik
Copy link

mahnunchik commented Mar 14, 2025

Describe the bug

The internal accounts array remains the same after switching the chain. This results in the accounts array containing incorrect addresses if different EVM chains use different addresses.

SDK Version (if relevant)

  • Client: @walletconnect/ethereum-provider
  • Version 2.19.0

To Reproduce
Steps to reproduce the behavior:

  1. Open wallet https://coin.space/wallet/ or any other wallet which uses different addresses for different chains
  2. Connect by WalletConnect to dApp like https://pancakeswap.finance/ or https://app.uniswap.org/swap or wagmi playground https://wagmi.sh/dev/contributing#_5-running-the-dev-playgrounds
  3. Switch chain
  4. Make sure that the account address remains the same, even though it should have changed, as different chains use different addresses

Example of a confirmed WalletConnect session namespaces:

{
    "eip155": {
        "chains": [
            "eip155:1",
            "eip155:42161",
            "eip155:56"
        ],
        "methods": [
            "eth_accounts",
            "eth_requestAccounts",
            "eth_sendRawTransaction",
            "eth_sign",
            "eth_signTransaction",
            "eth_signTypedData",
            "eth_signTypedData_v3",
            "eth_signTypedData_v4",
            "eth_sendTransaction",
            "personal_sign",
            "wallet_switchEthereumChain",
            "wallet_addEthereumChain",
            "wallet_getPermissions",
            "wallet_requestPermissions",
            "wallet_registerOnboarding",
            "wallet_watchAsset",
            "wallet_scanQRCode",
            "wallet_sendCalls",
            "wallet_getCapabilities",
            "wallet_getCallsStatus",
            "wallet_showCallsStatus"
        ],
        "events": [
            "chainChanged",
            "accountsChanged",
            "message",
            "disconnect",
            "connect"
        ],
        "accounts": [
            "eip155:1:0xB6bB59b3aC844e8e4A98A281D57E3E0628bcb471",
            "eip155:42161:0xAd8eDE8697aF92AF31Fe66EDAD9A52A74F74464E",
            "eip155:56:0x9B0d038121EB94CeA52FD08B416056B2824524dd"
        ]
    }
}

As you can see, different chains use different addresses.

Expected behavior

The account address is displayed correctly after switching the chain.

Additional context

At first, I thought it was an issue on the dApp side and created the following two issues:

After that, I realized that the issue is deeper and affects many dApps that use Wagmi:

And finally, I am here. Search for a solution has led me back to the WalletConnect library.

The accounts array is populated only once upon connection:

After the dApp page refresh:

this.setAccounts(namespace?.accounts);

But the accounts array does not update when switching the chain...

@mahnunchik mahnunchik added the type: bug Something isn't working label Mar 14, 2025
@mahnunchik
Copy link
Author

More context:

protected switchEthereumChain(chainId: number): void {
this.request({
method: "wallet_switchEthereumChain",
params: [{ chainId: chainId.toString(16) }],
});
}

The wallet_switchEthereumChain request is not sent to the connected wallet if the chain is already present in namespaces. I don't yet understand why this happens. If the chain is not in the confirmed namespaces, the request is sent to the wallet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant