Exthereum v0.1.0 Exthereum View Source

This library exists to present a convenient interface to control a full Ethereum node from Elixir, abstracting away the need to deal with the JSON-RPC API directly. It decodes the hex responses when necessary and functions return the idiomatic {:ok, data} | {:error, reason} tuples whenever possible. The goal is to cover the entire JSON-RPC API for Geth/Parity. This project has @specs for every function and is using Dialyzer + ExUnit.

So far I have “cherry picked” the most commonly used functions from https://github.com/ethereum/wiki/wiki/JSON-RPC.I plan to fill in the blanks. Pull requests welcomed. Because the goal is to fully manage an Ethereum node from Elixir, I have included some of the more commonly used Admin and Personal API functions which will require geth to be started with --rpcapi "db,eth,net,web3,personal". This should only be done in a safe network environment if at all.

UPDATE: Currently you can create accounts, unlock accounts, lock accounts, query balances, and send eth to anyone on the blockchain.

Examples

iex> Exthereum.client_version
{:ok, "Geth/v1.6.5-stable-cf87713d/darwin-amd64/go1.8.3"}

iex> Exthereum.sha3("0x68656c6c6f20776f726c64")
{:ok, "47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad"}

iex> Exthereum.net_version
{:ok, "1"}

iex> Exthereum.peer_count
{:ok, "19"}

iex> Exthereum.listening
{:ok, true}

iex> Exthereum.protocol_version
{:ok, 63}

iex> Exthereum.syncing
{:ok, false}

iex> Exthereum.coinbase
{:ok, false}

iex> Exthereum.mining
{:ok, true}

iex> Exthereum.hashrate
{:ok, "0"}

iex> Exthereum.gas_price
{:ok, 22061831512}

iex> Exthereum.accounts
{:ok, ["0x78fc2b9b6cf9b18f91037a5e0e074a479be9dca1",
  "0x141feb71895530f537c847d62f039d9be895bd35",
  "0xe55c5bb9d42307e03fb4aa39ccb878c16f6f901e",
  "0x50172f916cb2e64172919090af4ff0ba4638d8dd"]}

iex> Exthereum.block_number
{:ok, 3858216}

iex> Exthereum.get_balance("0xfE8bf4ca8A6170E759E89EDB5cc9adec3e33493f") # Donations accepted :-)
{:ok, 0.4650075166583676}

iex> Exthereum.transaction_count("0xfE8bf4ca8A6170E759E89EDB5cc9adec3e33493f")
{:ok, 3858216}

iex> Exthereum.new_account("h4ck3r", "h4ck3r")
{:ok, "50172f916cb2e64172919090af4ff0ba4638d8dd"}

iex> Exthereum.unlock_account("0xe55c5bb9d42307e03fb4aa39ccb878c16f6f901e", "h4ck3r")
{:ok, true}

iex> Exthereum.lock_account("0xe55c5bb9d42307e03fb4aa39ccb878c16f6f901e")
{:ok, true}

iex>  Exthereum.send_transaction("0xe55c5bb9d42307e03fb4aa39ccb878c16f6f901e", "0xfE8bf4ca8A6170E759E89EDB5cc9adec3e33493f", 0.00043, "h4ck3r")
{:ok, "88c646f79ecb2b596f6e51f7d5db2abd67c79ff1f554e9c6cd2915f486f34dcb"}

Link to this section Summary

Link to this section Functions

Link to this function accounts() View Source
accounts() :: {:ok, list} | {:error, String.t}
Link to this function block_number() View Source
block_number() :: {:ok, integer} | {:error, String.t}
Link to this function block_transaction_count_by_hash(hash) View Source
block_transaction_count_by_hash(String.t) ::
  {:ok, integer} |
  {:error, String.t}
Link to this function block_transaction_count_by_number(n) View Source
block_transaction_count_by_number(integer) ::
  {:ok, integer} |
  {:error, String.t}
Link to this function client_version() View Source
client_version() :: {:ok, String.t} | {:error, String.t}
Link to this function coinbase() View Source
coinbase() :: {:ok, String.t} | {:error, String.t}
Link to this function gas_price() View Source
gas_price() :: {:ok, String.t} | {:error, String.t}
Link to this function get_balance(account_hash) View Source
get_balance(String.t) :: {:ok, float} | {:error, String.t}
Link to this function get_storage_at(hash) View Source
get_storage_at(String.t) :: {:ok, integer} | {:error, String.t}
Link to this function hashrate() View Source
hashrate() :: {:ok, String.t} | {:error, String.t}
Link to this function listening() View Source
listening() :: {:ok, boolean} | {:error, String.t}
Link to this function lock_account(account) View Source
lock_account(account :: String.t) ::
  {:ok, String.t} |
  {:error, String.t}
Link to this function mining() View Source
mining() :: {:ok, boolean} | {:error, String.t}
Link to this function net_version() View Source
net_version() :: {:ok, String.t} | {:error, String.t}
Link to this function new_account(password, password_confirmation) View Source
new_account(password :: String.t, password_confirmation :: String.t) ::
  {:ok, String.t} |
  {:error, String.t}
Link to this function peer_count() View Source
peer_count() :: {:ok, integer} | {:error, String.t}
Link to this function protocol_version() View Source
protocol_version() :: {:ok, integer} | {:error, String.t}
Link to this function send_transaction(from, to, amount, password) View Source
send_transaction(from :: String.t, to :: String.t, amount :: float, password :: String) ::
  {:ok, String.t} |
  {:error, String.t}
Link to this function sha3(str_to_hash) View Source
sha3(String.t) :: {:ok, String.t} | {:error, String.t}
Link to this function syncing() View Source
syncing() :: {:ok, any} | {:error, String.t}
Link to this function transaction_count(hash) View Source
transaction_count(hash :: String.t) ::
  {:ok, integer} |
  {:error, String.t}
Link to this function uncle_count_by_block_hash(hash) View Source
uncle_count_by_block_hash(String.t) ::
  {:ok, integer} |
  {:error, String.t}
Link to this function uncle_count_by_block_number(n) View Source
uncle_count_by_block_number(integer) ::
  {:ok, integer} |
  {:error, String.t}
Link to this function unlock_account(account, password) View Source
unlock_account(account :: String.t, password :: String.t) ::
  {:ok, String.t} |
  {:error, String.t}