thirdweb-dev / js

Best in class web3 SDKs for Browser, Node and Mobile apps
https://thirdweb.com
Apache License 2.0
430 stars 327 forks source link

Coinbase wallet chain doesn't switch correctly #3623

Closed codingfarhan closed 1 month ago

codingfarhan commented 3 months ago

Hi guys,

I'm having trouble with executing transactions with coinbase wallet extension, as every single time I switch to a different chain (in this case, Sepolia) and try to execute a transaction, it gives me the following error:

underlying network changed (event="changed", network= {"name":"sepolia", " chainId": 11155111,"ens Address": null}, detectedNetwork= ["name". "homestead" "chainld":1"ensAddress"."0×00000000000C2 E074eC69A0dFb2997BA6C7d2e1e"}, code=NETWORK_ERROR, version=providers/5.7.2)

My packagees:

"@thirdweb-dev/react": "^4.6.2",
"@thirdweb-dev/sdk": "^4.0.63",
"@thirdweb-dev/wallets": "2.5.3",
"ethers": "^5",

It works sometimes, other times it shows me the error above. Would be a great help 🙏 .

Thanks!

joaquim-verges commented 3 months ago

can you share your code? One thing that i would say from experience is that it's safer to do do the switch chain first as a user click, then the transaction another user click. If done in quick succession the wallet often doesnt handle it well

codingfarhan commented 2 months ago

Hi, Im doing exactly as you said. There's a button to switch the chain (using useSwitchChain()) and once user is on the correct chain they get asked to execute the transaction. The transaction happens as follows:


if (txChainId !== chainId) {
      await switchChain(txChainId);
    } else {
      let transferTxResponse;

      try {
        transferTxResponse = await sdk?.wallet.transfer(message.to, message.value);
      } catch (e: any) {
        errorToast(e?.data?.message || e?.message);
        setIsClicked(false); // If process fails, we should allow user to try again
      }

.... and so on
jnsdls commented 2 months ago

yes this has been a problem with the v4 sdk for a while, likely not something we can fix in v4.

in order to make this work in v4:

jnsdls commented 2 months ago

I see now that it seems like you already do it in 2 steps... that is... very odd that it does not work in this case and something we'll likely have to look at. I would still assume that this will work in v5 (I believe we have tests for this even? if not we will add some)

codingfarhan commented 2 months ago

I see now that it seems like you already do it in 2 steps... that is... very odd that it does not work in this case and something we'll likely have to look at. I would still assume that this will work in v5 (I believe we have tests for this even? if not we will add some)

sure! please let me know if it works in v5! It'll be very helpful. Thanks.