Been struggling in finding a way to estimate gas for calling a function.
I was getting the error - Error: VM Exception while processing transaction: revert
locally on ganache and getting Error: The execution failed due to an exception.
on Kovan.
Here's a sample solidity function:
This is what my code looks like:
sig := []byte("withdraw(address)")
methodID := crypto.Keccak256(sig)[:4]
toAddress := common.HexToAddress(myAddr)
paddedAddress := common.LeftPadBytes(toAddress.Bytes(), 32)
var data []byte
data = append(data, methodID...)
data = append(data, paddedAddress...)
sendTo := common.HexToAddress(myAddress)
callMsg := ethereum.CallMsg{
From: Wallet.Address,
To: &sendTo,
Gas: 0,
GasPrice: big.NewInt(0),
Value: big.NewInt(0),
Data: data,
}
gasAmount, err := eth.EthClient.EstimateGas(context.Background(), callMsg)
Why am I getting the complaint - Error: VM Exception while processing transaction: revert