Is there a way on Nethereum to get the string messages returned from arevert or require are executed on solidity contract?

1 Answer 1

        var args = new ExecuteFunction { Revert = true, RevertMessage = "Fake Exception" };
        string actualRevertMessage = null;
            // 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}");

source: http://playground.nethereum.com/csharp/id/1050


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.