dominant-strategies / quais-5.js

MIT License
1 stars 6 forks source link

"from" field not populated in quai_estimateGas #7

Closed alejoacosta74 closed 10 months ago

alejoacosta74 commented 11 months ago

Ethers Version

5.7.2

Search Terms

No response

Describe the Problem

The estimateGas method on the signer (provider) does not include the from field as part of the JSON RPC request body. For example, when trying to estimate gas for a QRC20 deployment, Hardhat returns the error:

npx hardhat run scripts/estimateGasQuais.js --network cyprus1

Result:

Error: json-rpc-provider: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.quais.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (reason="execution reverted: ERC20: mint to the zero address", method="estimateGas", transaction={"gasLimit":{"type":"BigNumber","hex":"0x3d0900"},"data":"0x........5d\"}],\"id\":47,\"jsonrpc\":\"2.0\"}","requestMethod":"POST","url":"http://localhost:8610"}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/0.1.0)
  reason: 'execution reverted: ERC20: mint to the zero address',
  code: 'UNPREDICTABLE_GAS_LIMIT',
  method: 'estimateGas',

The equivalent Hardhat script using ethers.js returns an output that indicates that the from field is included in the RPC request body:

npx hardhat run scripts/estimateGasEthers.js --network cyprus1

Result:

Deployment error: Error: processing response error (body="{\"jsonrpc\":\"2.0\",\"id\":45,\"error\":{\"code\":-32000,\"message\":\"address is not in scope\"}}\n", error={"code":-32000}, requestBody="{\"method\":\"quai_estimateGas\",\"params\":[{\"from\":\"0x0b3be7ca8b8948a0f651ac681a4dff39e222d8d3\"}],\"id\":45,\"jsonrpc\":\"2.0\"}", requestMethod="POST", url="http://localhost:8610", code=SERVER_ERROR, version=web/0.1.0)
reason: 'processing response error',
  code: 'SERVER_ERROR',
  body: '{"jsonrpc":"2.0","id":45,"error":{"code":-32000,"message":"address is not in scope"}}\n',
  error: Error: address is not in scope

Code Snippet

const quais = require("quais");
const hre = require("hardhat");

async function main() {
  console.log(`using network ${hre.network.name}, endpoint ${hre.network.config.url}`);
  const ethersContract = await hre.ethers.getContractFactory("QRC20");
  const quaisProvider = new quais.providers.JsonRpcProvider(
    hre.network.config.url
  );

  const walletWithProvider = new quais.Wallet(
    hre.network.config.accounts[0],
    quaisProvider
  );
  await quaisProvider.ready;

  const QuaisContract = new quais.ContractFactory(
    ethersContract.interface.fragments,
    ethersContract.bytecode,
    walletWithProvider
  );
  try {
    const gas = await quaisProvider.estimateGas(
      QuaisContract.getDeployTransaction({ gasLimit: 4000000 }), 
    );
    console.log("Gas estimate:", gas.toString());

  } catch (error) {
    console.error(error);
  }
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error("Deployment error: ", error);
    process.exit(1);
  });

Contract ABI

This error is reproducible when deploying a QRC20 contract that contains a `_mint` function within the constructor.

Errors

Error: json-rpc-provider: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.quais.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (reason="execution reverted: ERC20: mint to the zero address", method="estimateGas", transaction={"gasLimit":{"type":"BigNumber","hex":"0x3d0900"},"data":"0x6d\"}],\"id\":47,\"jsonrpc\":\"2.0\"}","requestMethod":"POST","url":"http://localhost:8610"}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/0.1.0)
    at Logger.makeError (/Users/alejoacosta/code/quai/deploy-multi-chain-contract/node_modules/@quais/logger/src.ts/index.ts:269:28)
    at Logger.throwError (/Users/alejoacosta/code/quai/deploy-multi-chain-contract/node_modules/@quais/logger/src.ts/index.ts:281:20)
    at checkError (/Users/alejoacosta/code/quai/deploy-multi-chain-contract/node_modules/@quais/providers/src.ts/json-rpc-provider.ts:78:20)
    at JsonRpcProvider.<anonymous> (/Users/alejoacosta/code/quai/deploy-multi-chain-contract/node_modules/@quais/providers/src.ts/json-rpc-provider.ts:676:20)
    at step (/Users/alejoacosta/code/quai/deploy-multi-chain-contract/node_modules/@quais/providers/lib/json-rpc-provider.js:48:23)
    at Object.throw (/Users/alejoacosta/code/quai/deploy-multi-chain-contract/node_modules/@quais/providers/lib/json-rpc-provider.js:29:53)
    at rejected (/Users/alejoacosta/code/quai/deploy-multi-chain-contract/node_modules/@quais/providers/lib/json-rpc-provider.js:21:65)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  reason: 'execution reverted: ERC20: mint to the zero address',
  code: 'UNPREDICTABLE_GAS_LIMIT',
  method: 'estimateGas',
  transaction: {
    gasLimit: BigNumber { _hex: '0x3d0900', _isBigNumber: true },

Environment

Hardhat

Environment (Other)

No response

DenisIvanov26 commented 10 months ago

This is not a bug with quais. After looking at your repo, in the quais example you use provider.estimateGas() while in the ethers example you use the signer.estimateGas(). The from comes from using a walletwithprovider instead of just a provider when estimating Gas. if you use walletWithProvider in your quais example you will get the same output as in ethers.