How would you like to go about discussing defining the non-success error cases for things like eth_call
.
This is an interesting “error” response since the eth_call
can fail or a number of reasons (usual JSON RPC error, contract not found) and it can also fail and return data, such as the revert with reason
. Last time I checked, Geth and Parity differ in how they return this data.
Geth && Ganache:
{
"jsonrpc": "2.0",
"id": 824,
"result": "0x08c379a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000017494e56414c49445f4f524445525f5349474e4154555245000000000000000000"
}
Parity:
{
"jsonrpc": "2.0",
"id": 16,
"error": {
"code": -32015,
"data": "Reverted 0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f5452414e534645525f4641494c45440000000000000000000000000000000000",
"message": "VM execution error."
}
}
There are two things that are important here:
- The call reverted
- The revert returned some data,
revert with reason
With Geth/Ganache it is hard to determined if in fact the eth_call
was a Revert. Luckily no one has ran into a bytes4 collision with 0x08c379a
, yet…
Parity’s response alerts you to the fact that it did revert, though having to parse out the Reverted
string to detect this is inconvenient. I am also not 100% convinced that this is an error case, but am happy to be convinced otherwise.
I would like to discuss this case behave similar to a eth_call
success, but with the introduction of the status field. Status field behaves as expected with other JSONRPC calls:
status
- 1
if this transaction was successful or 0
if it failed
Revert With Reason:
{
"jsonrpc": "2.0",
"id": 16,
"status": "0x00",
"result": "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f5452414e534645525f4641494c45440000000000000000000000000000000000",
}
Revert:
{
"jsonrpc": "2.0",
"id": 16,
"status": "0x00",
"result": "0x",
}
Successful call:
{
"jsonrpc": "2.0",
"id": 16,
"status": "0x01",
"result": "0xcafe",
}
Standard error response:
{
"jsonrpc": "2.0",
"id": 1337,
"error": {
"code": -32000,
"message": "Invalid Input"
}
}