Is there a way on Nethereum to get the string messages returned from arevert or require are executed on solidity contract?
Asked
Active
Viewed 864 times
1 Answers
0
var args = new ExecuteFunction { Revert = true, RevertMessage = "Fake Exception" };
string actualRevertMessage = null;
try
{
// pretend we don't know this will fail, send the transaction
Console.WriteLine("* Execute - with args that will trigger a revert");
var executeFunctionHandler = web3.Eth.GetContractTransactionHandler<ExecuteFunction>();
// await executeFunctionHandler.SendRequestAndWaitForReceiptAsync(contractAddress, args);
await executeFunctionHandler.EstimateGasAsync(contractAddress, args);
}
// conditional catch
catch (Exception ex)
{
// a tx hash not been created because the error happened during estimation
Console.WriteLine($" [RpcResponseException]. Message: {ex.Message}");
// let's attempt to get the revert reason by querying with the same args
var revertException = await TryGetRevertMessage(web3, contractAddress, args);
if (revertException != null)
{
actualRevertMessage = revertException.Message;
}
}
Console.WriteLine($" [Expected Revert Reason]: {args.RevertMessage}");
Console.WriteLine($" [Actual Revert Reason]: {actualRevertMessage}");
Dennis Gonzales
- 1
- 1