Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to debug transactions in RSK network, which could be the best way?

We are running an RSK node, some smart contract transactions show internal errors, but the message related to the failed require condition doesn't appear in those error messages...

We only see "internal error" and are unable to see which specific error occurred.

like image 943
Julio Moros Avatar asked Feb 10 '21 20:02

Julio Moros


1 Answers

If your contract emits messages in the reversions, then you can find them out by using debug_traceTransaction.

NOTE: The debug RPC module is enabled by default in RSK config, but this is disabled on public nodes.

Furthermore, the RSK public nodes do not expose this feature, and you must run your own node in order to do so.

The following assumes that you have a local node running with RPC exposed on port 4444.

First, you need to enable debug module in your config file:

modules = [
    ...
    {
        "name": "debug",
        "version": "1.0",
        "enabled": "true",
    },
    ...
]

Then, you can execute the RPC method passing the transaction ID as a parameter, like in this example:

curl \
    -X POST \
    -H "Content-Type:application/json" \
    --data '{"jsonrpc":"2.0","method":"debug_traceTransaction","params":["0xa9ae08f01437e32973649cc13f6db44e3ef370cbcd38a6ed69806bd6ea385e49"],"id":1}' \
    http://localhost:4444

You will get the following response (truncated for brevity):

{
    ... 
    "result": "08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001e536166654d6174683a207375627472616374696f6e206f766572666c6f770000",
    "error": "",
    "reverted": true,
    ...
}

Finally, convert result from hexadecimal to ASCII, to obtain a readable message:

Ãy  SafeMath: subtraction overflow
like image 111
7alip Avatar answered Oct 14 '22 07:10

7alip