ethers.js: SERVER_ERROR and INVALID_ARGUMENT errors for version 5.4.1

but the same code works fine with ethers version 5.3.1

The code

const provider = new ethers.providers.JsonRpcProvider('https://kovan.infura.io/v3/37d...');
const providerContract = new ethers.Contract(contractAddress, abi, provider);

const wallet = new ethers.Wallet('1234....')
const providerWallet = wallet.connect(provider)
const signerContract = providerContract.connect(providerWallet);

let txHash = await signerContract['safeTransferFrom(address,address,uint256)'](from, to, tokenId, { gasPrice: ethers.utils.parseUnits(30, "gwei") })
await txHash.wait()

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 41 (15 by maintainers)

Commits related to this issue

Most upvoted comments

Hey there, I’m “the alchemy engineer” 😃 Just updated our eth_estimateGas endpoint so the legacy type 0x0 should now work. Sorry for all of this inconvenience and thanks for everyone’s patience. Also thanks to @ricmoo for diagnosing.

This has been fixed in 5.4.3.

For future reference, anyone who happens across this issue, the cause was an bug in the JsonRpcProvider for estimateGas and call on networks which did not implement EIP-2930 (Berlin), which is why it only showed up on Kovan (which at this time has not implemented the Berlin hard fork from earlier this year).

For a network that supports Berlin, the type field is allowed in call and estimateGas calls and the JsonRpcProvider would use a type of 0 to indicate legacy operation. Before Berlin though, type was extraneous and therefore error out.

The EtherscanProvider worked fine though (I guess they ignore random other properties), which is why the default provider also worked; all the JSON-RPC backed providers would throw an error, but the EtherscanProvider in the mix picked up the slack.

Anyhoo, it should be fixed. But please let me know if you continue to experience any issues. 😃

Oh, interesting. I didn’t realize the consensus engine wasn’t available in Geth, but that kinda makes sense.

Ok, I’ll reach out. Thanks! 😃

aight an alchemy engineer let me know he thinks its a parity bug 👍

Can you please include the full error?

here’s your concise example lmao:

import * as ethers from 'ethers';

const provider = new ethers.providers.JsonRpcProvider(
  'https://kovan.infura.io/v3/590d1a16f5b642a8b89bd2cee1d598de',
);

const wallet = new ethers.Wallet(process.env.KEY!, provider);

wallet.sendTransaction({ to: wallet.address, value: 0 });
james@Sisyphus ~/devel/optics-monorepo/typescript/optics-deploy                                                                                                                                                [15:37:00] 
> $ npx ts-node ./tmp.ts                                                                                                                                                              ⬡ 15.14.0 [±prestwich/eth-helper ✓]

/Users/james/devel/optics-monorepo/typescript/optics-deploy/node_modules/@ethersproject/logger/src.ts/index.ts:213
        const error: any = new Error(message);
                           ^
Error: cannot estimate gas; transaction may fail or may require manual gas limit (error={"reason":"processing response error","code":"SERVER_ERROR","body":"{\"jsonrpc\":\"2.0\",\"id\":49,\"error\":{\"code\":-32602,\"message\":\"Invalid params\"}}","error":{"code":-32602},"requestBody":"{\"method\":\"eth_estimateGas\",\"params\":[{\"gasPrice\":\"0x12a05f200\",\"type\":\"0x0\",\"from\":\"0xa4849f1d96b26066f9c631fcdc8f1457d27fb5ec\",\"to\":\"0xa4849f1d96b26066f9c631fcdc8f1457d27fb5ec\"}],\"id\":49,\"jsonrpc\":\"2.0\"}","requestMethod":"POST","url":"https://kovan.infura.io/v3/590d1a16f5b642a8b89bd2cee1d598de"}, tx={"to":{},"value":0,"from":"0xa4849f1D96B26066f9C631FCdc8F1457D27Fb5EC","gasPrice":{"type":"BigNumber","hex":"0x012a05f200"},"type":0,"nonce":{},"gasLimit":{},"chainId":{}}, code=UNPREDICTABLE_GAS_LIMIT, version=abstract-signer/5.4.0)
    at Logger.makeError (/Users/james/devel/optics-monorepo/typescript/optics-deploy/node_modules/@ethersproject/logger/src.ts/index.ts:213:28)
    at Logger.throwError (/Users/james/devel/optics-monorepo/typescript/optics-deploy/node_modules/@ethersproject/logger/src.ts/index.ts:225:20)
    at /Users/james/devel/optics-monorepo/typescript/optics-deploy/node_modules/@ethersproject/abstract-signer/src.ts/index.ts:300:31
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at async Promise.all (index 6)