Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot estimateGas using provider sometimes #4938

Open
gauravmindzk opened this issue Feb 3, 2025 · 0 comments
Open

cannot estimateGas using provider sometimes #4938

gauravmindzk opened this issue Feb 3, 2025 · 0 comments
Assignees
Labels
investigate Under investigation and may be a bug. v6 Issues regarding v6

Comments

@gauravmindzk
Copy link

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

@gauravmindzk gauravmindzk added investigate Under investigation and may be a bug. v6 Issues regarding v6 labels Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigate Under investigation and may be a bug. v6 Issues regarding v6
Projects
None yet
Development

No branches or pull requests

2 participants