I would like to estimate the amount of gas required for a transaction before actually sending it with web3. For some reason I always get a gas exceeded error. I've double-checked my solidity code and there are no errors failing during this function call. Does anyone know why estimateGas()
does not work for my use case?
My Code:
from web3 import Web3, HTTPProvider
web3 = Web3(HTTPProvider('https://mainnet.infura.io/v3/{LONG_INFURA_PROJECT_ID}'))
abi = [ ... long abi ...]
MyContract = web3.eth.contract(address="[contract_address]", abi=abi)
# this line fails...
# note: contractMethod is the name of the contract function I'm trying to call
estimated_gas = MyContract.functions.contractMethod("some_param").estimateGas()
Once I try to execute the line where estimateGas()
is called, I get the following error:
{'code': -32000, 'message': 'gas required exceeds allowance (124572510) or always failing transaction'}
contractMethod
?contractMethod
is a placeholder name for the name of the function I am calling on the contractMyContract
estimateGas()
is independent of the function call. I get this error no matter what method I try to invoke on the function. I am fairly new to ethereum dev, so I apologize if the information I've included in the question is not sufficient for help or different than you require/expect. I can update this if necessary.