Nethereum: Error `gas required exceeds allowance or always failing transaction` when requesting estimation for Transfer ERC20 method
By looking at the last 2 commits from master I kinda extracted the way to do contract estimation (until a new Neth version is published), this way:
[<Function("transfer", "bool")>]
type TransferFunctionFromErc20TokenContract(recipient: string, tokenAmount: int) =
inherit ContractMessage()
[<Parameter("address", "_to", 1)>]
member val To = recipient with get
[<Parameter("uint256", "_value", 2)>]
member val TokenAmount = tokenAmount with get
let contractHandler = ethWeb3Infura.Eth.GetContractHandler(DAI_CONTRACT_ADDRESS)
let amountInWei: int = 50000
let transferFunctionMsg = TransferFunctionFromErc20TokenContract(destination, amountInWei)
(contractHandler.EstimateGasAsync transferFunctionMsg).Wait()
But it fails with:
System.AggregateException: One or more errors occurred. ---> Nethereum.JsonRpc.Client.RpcResponseException: gas required exceeds allowance or always failing transaction
at Nethereum.JsonRpc.Client.RpcClient.HandleRpcError (Nethereum.JsonRpc.Client.RpcMessages.RpcResponseMessage response) [0x00036] in <63612088e09f4c37bab92e99c0fd4d66>:0
at Nethereum.JsonRpc.Client.RpcClient+<SendInnerRequestAync>d__12`1[T].MoveNext () [0x000c2] in <63612088e09f4c37bab92e99c0fd4d66>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <2722d81e5b26475cb5f475fea055f291>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <2722d81e5b26475cb5f475fea055f291>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <2722d81e5b26475cb5f475fea055f291>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <2722d81e5b26475cb5f475fea055f291>:0
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <2722d81e5b26475cb5f475fea055f291>:0
at Nethereum.JsonRpc.Client.ClientBase+<SendRequestAsync>d__4`1[T].MoveNext () [0x0014f] in <c416a5b7c6fc4f408e486f123dc07c0a>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <2722d81e5b26475cb5f475fea055f291>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <2722d81e5b26475cb5f475fea055f291>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <2722d81e5b26475cb5f475fea055f291>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <2722d81e5b26475cb5f475fea055f291>:0
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <2722d81e5b26475cb5f475fea055f291>:0
at Nethereum.Contracts.FunctionBase+<EstimateGasFromEncAsync>d__21.MoveNext () [0x0007e] in <55ebf98ce6764680bf757bac817b9f23>:0
--- End of inner exception stack trace ---
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 23 (21 by maintainers)
I have solved the problem of not able to call another function from a contract (EA calls contract A’s function -> Contract A calls B’s function -> Contract B ) which was the problem with the solidity version. Above 4.22 version, in order to call another function from a different contract, you need to add
“config”: { “chainId”: 15, “homesteadBlock”: 0, “EIP150Block”: 0, “eip155Block”: 0, “eip158Block”: 0, “ByzantiumBlock”: 0 }
“ByzantinumBlock”:0 inside your genesis.json file. Then you will be able to call another function from another contract.
If you get exceeds block gas limit, try setting the gas limit of the genesis.json into something like “gasLimit”: “0x8000000”,
this.
Hope this helps.