Skip to content

esprezzo/elixir-perkle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Elixir-Perkle

Elixir interface to Perkle JSON-RPC w/smart contract support

This library presents a convenient interface to control one or more Perkle nodes using the Elixir programming language. It abstracts away the need to deal with the JSON-RPC API directly and handles hex encoding/decoding when needed.

Functions return the idiomatic {:ok, data} | {:error, reason} tuples whenever possible. The goal is to cover the entire JSON-RPC API of the standard Geth implemetation.

This project aims to have @specs for every function and is using Dialyzer + ExUnit for testing/linting.

Recent Additions:

  • Smart Contract deployment
  • ABI registration
  • Filter registration
  • Tx receipt retrieval
  • Token

Pull requests welcomed. This library also includes some of the more commonly used "admin" and "personal" API functions which will require the node to be started with --rpcapi "db,eth,net,web3,personal". The sensitive interfaces should only be done in a safe network environment if at all.

Examples of Currently Implemented JSON-RPC methods

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

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

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

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

iex> Perkle.listening
{:ok, true}

iex> Perkle.protocol_version
{:ok, 63}

iex> Perkle.syncing
{:ok, false}

iex> Perkle.coinbase
{:ok, "78fc2b9b6cf9b18f91037a5e0e074a479be9dca1"}

iex> Perkle.mining
{:ok, true}

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

iex> Perkle.gas_price
{:ok, 22061831512}

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

iex> Perkle.block_number
{:ok, 3858216}

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

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

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

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

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

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

Complete list of currently implemeted features:

Eth Namespace Functions

- defdelegate get_transaction_by_hash(hash), to: Eth
- defdelegate get_transaction_receipt_by_hash(hash), to: Eth
- defdelegate get_block_by_hash(hash, full_txns), to: Eth
- defdelegate get_block_by_number(number, full \\ false), to: Eth
- defdelegate get_balance(account_hash), to: Eth
- defdelegate protocol_version(), to: Eth
- defdelegate syncing(), to: Eth
- defdelegate coinbase(), to: Eth
- defdelegate mining(), to: Eth
- defdelegate hashrate(), to: Eth
- defdelegate gas_price(), to: Eth
- defdelegate accounts(), to: Eth
- defdelegate block_number(), to: Eth
- defdelegate transaction_count(hash), to: Eth
- defdelegate get_filter_changes(hash), to: Eth
- defdelegate eth_call(params), to: Eth
- defdelegate eth_send(transaction), to: Eth, as: - :eth_send_transaction
- defdelegate uninstall_filter(id), to: Eth
- defdelegate new_filter(map), to: Eth

Web3 Namespace Functions

- defdelegate client_version(), to: Web3
- defdelegate sha3(str), to: Web3

Net Namespace Functions

- defdelegate version(), to: Net
- defdelegate peer_count(), to: Net
- defdelegate listening(), to: Net

Personal Namespace Functions

- defdelegate new_account(password, password_confirmation), to: Personal
- defdelegate unlock_account(account, password), to: Personal
- defdelegate lock_account(account), to: Personal
- defdelegate send_transaction(from, to, amount, password), to: Personal

Aggregate/Stats Functions

- defdelegate get_recent_averages(sample_size), to: Aggregates
- defdelegate get_recent_blocks(sample_size), to: Aggregates
- defdelegate get_recent_blocktimes(sample_size), to: Aggregates
- defdelegate get_recent_blocks_with_blocktimes(sample_size), to: Aggregates
- defdelegate get_recent_transactions_per_block(sample_size), to: Aggregates
- defdelegate get_average_blocktime(blocks), to: Aggregates
- defdelegate get_average_difficulty(blocks), to: Aggregates

Encoding + Utils

- defdelegate unhex(str), to: HexUtils
- defdelegate to_hex(str), to: HexUtils
- defdelegate is_valid_address?(address), to: HexUtils
- defdelegate hex_to_decimal(hex_string), to: HexUtils

ABI Functions

defdelegate load_abi(file), to: ABI
defdelegate reformat_abi(abi), to: ABI
defdelegate abi_method_signature(abi, name), to: ABI, as: :method_signature
defdelegate encode_abi_event(signature), to: ABI, as: :encode_event
defdelegate encode_abi_data(signature), to: ABI, as: :encode_data
defdelegate encode_abi_options(options, keys), to: ABI, as: :encode_options
defdelegate encode_abi_option(value), to: ABI, as: :encode_option
defdelegate encode_abi_method_call(abi, name, input), to: ABI, as: :encode_method_call
defdelegate decode_abi_data(types_signature, data), to: ABI, as: :decode_data
defdelegate decode_abi_output(abi, name, output), to: ABI, as: :decode_output
defdelegate decode_abi_event(data, signature), to: ABI, as: :decode_event
defdelegate abi_keys_to_decimal(map, keys), to: ABI, as: :keys_to_decimal

Installation

hex.pm

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `perkle` to your list of dependencies in `mix.exs`:
def deps do
  [{:perkle, "~> 0.1.0"}]
end

Right now you should use the Github:
def deps do
  [{:perkle, "GITHUB_ADDRESS"}]
end

Documentation can be generated with ExDoc

Releases

No releases published

Packages

No packages published

Languages