Ethereumex Build Status

Elixir JSON-RPC client for the Ethereum blockchain

Installation

Add Ethereumex to your mix.exs dependencies:

  1. Add ethereumex to your list of dependencies in mix.exs:
def deps do
[{:ethereumex, "~> 0.1.2"}]
end
  1. Ensure ethereumex is started before your application:
def application do
[applications: [:ethereumex]]
end

Configuration

In config/config.exs, add Ethereum protocol host params to your config file

config :ethereumex,
scheme: "http",
host: "localhost",
port: 8545

Usage

Available methods:

Examples

iex> Ethereumex.HttpClient.web3_client_version
{:ok,
%{"id" => 0, "jsonrpc" => "2.0",
"result" => "Geth/v1.6.5-stable-cf87713d/darwin-amd64/go1.8.3"}}
iex> Ethereumex.HttpClient.web3_sha3(["wrong_param"])
{:error,
%{"code" => -32602,
"message" => "invalid argument 0: missing 0x prefix for hex data"}}
iex> Ethereumex.HttpClient.eth_get_balance(["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "latest"])
{:ok, %{"id" => 2, "jsonrpc" => "2.0", "result" => "0x0"}}

Note that all method names are snakecases, so, for example, shh_getMessages method has corresponding Ethereumex.HttpClient.shh_get_messages/1 method

Custom requests

Many Ethereum protocol implementations support additional JSON-RPC API methods. To use them, you should call Ethereumex.HttpClient.send_request/2 method.

For example, let's call geth's rpc_modules method.

iex> Ethereumex.HttpClient.send_request("rpc_modules")
{:ok,
%{"id" => 5, "jsonrpc" => "2.0",
"result" => %{"eth" => "1.0", "net" => "1.0", "rpc" => "1.0",
"web3" => "1.0"}}}

Contributing

  1. Fork it!
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Author

Ayrat Badykov (@ayrat555)

License

Ethereumex is released under the MIT License.