Skip to content

cannot estimateGas using provider sometimes #4938

Open
@gauravmindzk

Description

@gauravmindzk

Ethers Version

6.10.0

Search Terms

No response

Describe the Problem

When I run the below code as a standalone nodejs script , I get the estimated gas with provider but when trying it in my server or in hardhat test cases , it throws error .

this code works when I pass 'wallet' instead of 'provider'

What is the issue ?

Code Snippet

const { ethers } = require("ethers");

const provider = new ethers.JsonRpcProvider(
    "https://sepolia.infura.io/v3/key"
);

const CONTRACT_ADDRESS = "ERC721-contract-address"
const PRIVATE_KEY = "my-private-key";

const abi = standardERC721ABI

function createEthersContractMethodInstance(provider, smartContractAddress, abi) {
    try {
      const contract = new ethers.Contract(smartContractAddress, abi?.abi ?? abi, provider);
      return contract;
    } catch (error) {
      console.log("createEthersContractMethodInstance error -->", error);
      throw error;
    }
}

const estimateFunctionCallGas = async() => {
    // Create a new wallet instance
    const wallet = new ethers.Wallet(PRIVATE_KEY, provider);
    const contract_Methods = createEthersContractMethodInstance(provider,CONTRACT_ADDRESS,abi)
    const gasEstimate = await contract_Methods["mintToken"].estimateGas("0x27385c105d4ef3a20d6dd579bbb417dea318114b", "123458", "https://example.com/metadata/123458");
    const gasEstimate1 = await contract_Methods.mintToken.estimateGas("0x27385c105d4ef3a20d6dd579bbb417dea318114b", "123458", "https://example.com/metadata/123458");
    console.log("gas estimate :",gasEstimate)
    console.log("gas estimate 1: ",gasEstimate1)
}
estimateFunctionCallGas();

Contract ABI

Errors

Error: execution reverted (unknown custom error) (action="estimateGas", data="0xe2517d3f00000000000000000000000000000000000000000000000000000000000000009f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6", reason=null, transaction={ "data": "0x731133e90000000000000000000000008c4f69e9bbd1c837cd59a0bcf19f2498f8eda5980000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000", "to": "0x00EE826B3027CD0A32Ce5B8EFe47c4bd80f19C22" }, invocation=null, revert=null, code=CALL_EXCEPTION, version=6.10.0)
      at makeError (node_modules\ethers\src.ts\utils\errors.ts:694:21)
      at getBuiltinCallException (node_modules\ethers\src.ts\abi\abi-coder.ts:118:21)
      at Function.getBuiltinCallException (node_modules\ethers\src.ts\abi\abi-coder.ts:235:16)
      at JsonRpcProvider.getRpcError (node_modules\ethers\src.ts\providers\provider-jsonrpc.ts:979:32)
      at C:\Users\gaura\Desktop\ERC2771\erc1155-gasless-hardhat\node_modules\ethers\src.ts\providers\provider-jsonrpc.ts:563:45
      at processTicksAndRejections (node:internal/process/task_queues:95:5)

Environment

No response

Environment (Other)

No response

Metadata

Metadata

Assignees

Labels

investigateUnder investigation and may be a bug.v6Issues regarding v6

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions