So, I'm making a private network and deploying some contracts. The contract has a payable method which means I have to put value when calling the method. I want to get the estimated cost to call the method using this function in web3.py
contract = w3.eth.contract(address=address, abi=abi)
transaction = contract.functions.someMethod().buildTransaction({
'from': someUserAddress,
'value': someValue
})
print(w3.eth.estimate_gas(transaction))
This works fine for user that has balance in their wallet. But, for user that has 0 balance in their wallet, this method is not working. This error must be show up
ValueError: {'code': -32000, 'message': 'err: insufficient funds for gas * price + value: address <someUserAddress> have 0 want <someValue> (supplied gas xxxxxxx)'}
I need to estimate gas first so the user can know how much they must top up the balance to call the method and not blindly to up the balance. Is there any way to do this?