Etherex

Etherex is an Elixir high level library for the Ethereum blockchain. It is is based on the methods of the Json RPC API of Ethereum relying on library Ethreumex.

Ethereum Clients (or nodes or EVMs)

Similar Applications

Note. There is tool already named Etherex (https://github.com/etherex/etherex). The tool allows exchange in Ethereum by using a set of contracts.

TODO

< "error": {
< "message": "VM Exception while processing transaction: revert not creator",
< "code": -32000,
< "data": {
< "0xda850732121ff8b49f2922a40568ac8ecc2e2b6b46ce2f9a949184debfd33032": {
< "error": "revert",
< "program_counter": 216,
< "return": "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b6e6f742063726561746f72000000000000000000000000000000000000000000",
< "reason": "not creator"
< },
< "stack": "c: VM Exception while processing transaction: revert not creator\n at Function.c.fromResults (/home/angel/node_modules/ganache-cli/build/ganache-core.node.cli.js:4:194812)\n at w.processBlock (/home/angel/node_modules/ganache-cli/build/ganache-core.node.cli.js:42:53376)\n at runMicrotasks (<anonymous>)\n at processTicksAndRejections (internal/process/task_queues.js:97:5)",
< "name": "c"

Nevertheless, this message is specifically from Ganache (in non-compliant mode), so in a real blockchain that doesn’t work. The only way to return a result from a state-changing method is to use logs (called events in Solidity), but a revert (which is how require works) also rolls back all logs.

The responses eth_sendTranscation in other Ethereum clients can be hash (try test/etherex_error_test.exs with Openethereum or Geth).

Just to show the response to the same request in different clients:

13:35:12.843 [warn] %{"code" => -32000, "data" => %{"0x4983a9bb2ef373ca1797b1d692befdda12e4e3f54804a4feff305eb2787daec7" => %{"error" => "revert", "program_counter" => 294, "reason" => "message_of_revert", "return" => "0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000116d6573736167655f6f665f726576657274000000000000000000000000000000"}, "name" => "c", "stack" => "c: VM Exception while processing transaction: revert message_of_revert\n at Function.c.fromResults (/home/angel/node_modules/ganache-cli/build/ganache-core.node.cli.js:4:194812)\n at /home/angel/node_modules/ganache-cli/build/ganache-core.node.cli.js:42:52863"}, "message" => "VM Exception while processing transaction: revert message_of_revert"}
12:59:50.382 [warn] %{"code" => -32015, "data" => "Reverted 0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000116d6573736167655f6f665f726576657274000000000000000000000000000000", "message" => "VM execution error."}
13:39:19.953 [warn] %{"code" => 3, "data" => "0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000116d6573736167655f6f665f726576657274000000000000000000000000000000", "message" => "execution reverted: message_of_revert"}

In Openethereum and Geth, the first 4 bytes (08c379a0) are the function selector - they can be discarded in order to get the actual error:

iex(2)> data = "000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000116d6573736167655f6f665f726576657274000000000000000000000000000000"
iex(3)> data |> Base.decode16!(case: :lower) |> ABI.TypeDecoder.decode_raw([:string])
["message_of_revert"]
defmodule SolidityExamples.Counter do
use Etherex.SolidityContract, source: "priv/solidity/Counter.sol"
end

Supported API

According to Openethereum wiki (https://openethereum.github.io/), these are the APIs although not all of them are enabled:

Non standard API

Requirements

Use and tests

sudo add-apt-repository ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install solc
cd $HOME
npm install ganache ethnode
PATH=$HOME/node_modules/.bin:$PATH

Start Ethereum in a terminal

You can use ethnode

ethnode openethereum

or ganache

ganache-cli

Compile and start Elixir in other terminal

mix deps.get
mix compile
iex -S mix

Documentation

Add etherex to your list of dependencies in mix.exs:

def deps do
[
{:etherex, "~> 1.0.0-rc19"}
]
end

Documentation can be generated with ExDoc:

mix docs