0

Suppose an ethereum smart contract has external function "foo" whose logic has state-reverting exception require(1 == 0, 'error: you broke the simulation!');.

If ethereum-client A broadcasts transaction "txA" which is a function call on foo, how can ethereum-client B access the state-reverting message corresponding to "txA"?

edit: by "how can", I mean how can a developer practically enable ethereum-client B to access this data. i.e. Can you please point me in the direction of the correct (lower-level.. not webui) api/rpc call from a particular tool?

Clearly this is possible since block explorers provide such messages for failed transactions. I read through some of the source of etherscan, but their javascript is minimized and not easily readable.

Thanks in advance!

  • I've also been digging through the source of go-ethereum, as well as Metamask to find a solution, to no avail. (yet?). I've also surveyed the list of possible rpc calls to nodes in this network, and the closest thing I found is "getTransactionLogs". Unfortunately, these logs appear to be only for transactions that have been included in blocks, which is not the case when a function reverts. – georgearchon Mar 04 '20 at 00:43

1 Answers1

0

See this: https://ethereum.stackexchange.com/questions/39817/are-failed-transactions-included-in-the-blockchain

Failed transactions often are included in the chain.

What you sometimes see, if you're using e.g. MetaMask, is a popup saying "this transaction will fail" that happens before the transaction is sent to the chain. This is MetaMask trying to be helpful and prevent you wasting gas. But you can force send the transaction anyway, and you'll get a failed/reverted transaction posted on-chain (like this one for this Solidity source).

So to answer the original question, if TxA was posted on-chain, then client B will process it and get the revert message itself. If TxA was not posted on-chain, then there is no record of it.

K S
  • 141
  • 3
  • I appreciate your theoretical affirmation that it can be done. My original question was ` how can ethereum-client B access the state-reverting message corresponding to "txA"?` So as a developer, using api (or rpc calls) calls from any of the various tools (go-ethereum etc), how can etherum-client B access this data? Which api (or rpc) calls from which tool? – georgearchon Mar 05 '20 at 17:11
  • I use Nethereum, the .NET api, and the call is web3.Eth.GetContractTransactionErrorReason which gets passed a tx hash and returns a string. Sample usage here: http://playground.nethereum.com/csharp/id/1050. I dont know what the webjs equivalent is. Also, I believe there is still a constraint that the client has to be geth (parity may have some issues). – K S Mar 06 '20 at 12:47