ethers-io / ethers.js

Complete Ethereum library and wallet implementation in JavaScript.
https://ethers.org/
MIT License
7.9k stars 1.83k forks source link

Sending transaction with data on Coinbase Wallet Mobile fails #4816

Open comster opened 4 weeks ago

comster commented 4 weeks ago

Ethers Version

6.13.2

Search Terms

coinbase

Describe the Problem

Trying to send a transaction with data, or a contract call, are not working on coinbase wallet mobile browser. It's working in the browser with coinbase wallet, and metamask, and metamask mobile. I approve the transaction, but then get an RPC error: "Failed to sign transaction".

Things I have done to debug:

Code Snippet

No response

Contract ABI

No response

Errors

could not coalesce error (error={ "code": -32603, "data": { "originalError": { } }, "message": "Failed to sign transaction" }, payload={ "id": 6, "jsonrpc": "2.0", "method": "eth_sendTransaction", "params": [ { "data": "0x000000000...", "from": "0xafac00f3b608ddc9df671225029844d76a10af6d", "gas": "0x8f77", "to": "0x5493db14a2b6fd71b531fa1cfc752fdfad734acd", "value": "0x16bcc41e900000" } ] }, code=UNKNOWN_ERROR, version=6.13.0)

Environment

Ethereum (mainnet/ropsten/rinkeby/goerli), Other (please specify)

Environment (Other)

Coinbase Wallet Mobile Browser

ricmoo commented 4 weeks ago

Hmmm. I haven’t used coinbase wallet. Is it a browser plugin, similar to MetaMask?

How are you creating the Signer?

comster commented 4 weeks ago

Thanks for your help! Ya, it's similar to MetaMask afaik. Again, it's only on mobile in their in app browser where this isn't working, which is strange. And if I remove the data it works fine.

let provider = new ethers.BrowserProvider(window.ethereum);
let signer = await provider.getSigner();
const tx = await signer.sendTransaction({
  to: toAddress,
  value: ethers.parseEther(amount),
  data: ethers.AbiCoder.defaultAbiCoder().encode([{"name":"_value","type":"string"}], [DATA_VALUE_UNENCODED])
});
comster commented 4 weeks ago

And for DATA_VALUE_UNENCODED of a single character string like "Z" works, but not for "ZA" 🤔

ricmoo commented 4 weeks ago

That’s is super weird. :p

I’m guessing no console? If it is on iOS can you connect it to Safari and see any other errors in the console?

Do they have a GitHub repo? With issues we can search?

comster commented 4 weeks ago

No I don't think so. It's an embedded browser in their app. It's not open source. I've reached out to them but haven't had a response yet. Just curious if you have any tips on other things I could test or debug. I can't tell if this is an issue with my code, ethers, or the wallet provider. Smells like the wallet provider, but I assume others aren't having this issue. Otherwise I'm giving up and going to restart my project with the newer react components available 🤷 .

comster commented 2 weeks ago

For anyone else experiencing this issue, it turns out I had to figure out the gasLimit myself.

Any insight into where in the stack this issue is at? I assume it's the coinbase wallet not properly calculating the gaslimit themselves, based on the data/input size. It would be great to raise this issue with the appropriate channel to help resolve this.

        const transactionRequest = {
          to: address,
          value: amount,
          data: getEncodedEthData(data_str),
        };
        const estimatedGas = await signer.estimateGas(transactionRequest);
        const gasLimit = estimatedGas * BigInt(1000) / BigInt(100); // 10x the gas price for coinbase mobile wallet
        const tx = await signer.sendTransaction({
          ...transactionRequest,
          gasLimit: gasLimit,
        });