Closed codingfarhan closed 1 month 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
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
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:
sdk.wallet.transfer
gets called at least on the next JS tick (meaning you could try wrapping the transfer call in a setTimeout(() => {/* your code to transfer here */}, 0)
and that should make it workif that is still flakey then the guaranteed way to make it work is to split it into 2 user interactions:
that said I believe this behavior is fixed in v5 of the SDK, so if upgrading is an option that should do it, too
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)
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.
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:
It works sometimes, other times it shows me the error above. Would be a great help 🙏 .
Thanks!