estimate the gasLimit for calling a function in a smartcontract ethers.js is erroring out #1923
Replies: 12 comments 3 replies
-
What signer are you using? Ethers should t be emitting anything with the error What provider are you using? |
Beta Was this translation helpful? Give feedback.
-
attackArbitrageOpportunity i just a console.log that I added. Here is signer and provider code
|
Beta Was this translation helpful? Give feedback.
-
Oh! I see. :) This error just means your node cannot guess how much it will cost to run the transaction. This can happen for a few reasons; 1) if there is a revert in your contract, it may be getting triggered, 2) the execution cost of the transaction exceeds the configured transaction or block gas limit, 3) sometimes a node seems to just “give up” on estimating, often (bit not always?) when it calls out to other contracts. Do any of those cases seem possible? |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
thanks for your response! is there a way to calculate gas limit for calling this function? do you think it is worth checking out estimateGas function of web or something similar? |
Beta Was this translation helpful? Give feedback.
-
The estimateGas function just calls the estimateGas of the provider, so there is nothing interesting internal to examine. And that just simulates the execution in the Provider’s node, which runs the EVM code with the available blockchain data (contract data, bytecode, etc). Also make sure your node is synced. The best thing to do is to look at the contract source to figure out what could be unpredictable. If you are certain the contract will succeed, you can try using a much higher gas limit for now to get an idea of how mu it will cost, then you can hard-code a reasonable worst-case value. I generally use values baked into the ABI. |
Beta Was this translation helpful? Give feedback.
-
Given that output error from @ishan-verma, how does one parse it since it's all returned as a string?
|
Beta Was this translation helpful? Give feedback.
-
Parse the |
Beta Was this translation helpful? Give feedback.
-
Parse the |
Beta Was this translation helpful? Give feedback.
-
@EvilJordan Can you provide a concise example? I’m not sure where in that sample you are getting a string thrown. If that is the case, it is certainly a bug. If you use string concatenation with an error (e.g. |
Beta Was this translation helpful? Give feedback.
-
I am tried calling a function in my smart contract, and for estimating gas for a function, I used the below code and its worked,
Hope it helps! |
Beta Was this translation helpful? Give feedback.
-
I think we don't even need to pass the gas limit and gas price as it can be automatically set. Example with overridden gas limit and gas price. contract.methodName(
params,
{ gasLimit: ethers.utils.hexlify(250000), gasPrice: ethers.utils.parseUnits('5', "gwei") },
); with automated gas limit and gas price set by ether contract.methodName(
params
); Hope this will help. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to estimate the gasLimit for calling a function in a smartcontract but ethers.js is erroring out
[Error caught attackArbitrageOpportunity: Error: cannot estimate gas; transaction may fail or may require manual gas limit (method="estimateGas", transaction={"from":"0x652694fe1f10D0dEc1BGR9496bB7220d7799","gasPrice":{"type":"BigNumber","hex":"0x1f4add4dac"},"to":"0x8Daa352694fe1f10D549d4B496b8f0a38B76668a3106","data":"0x0c5c9fa800000000000000000000a0b86991c6218b36
here is the code
Beta Was this translation helpful? Give feedback.
All reactions