• Stars
    star
    115
  • Rank 296,032 (Top 6 %)
  • Language
    Elixir
  • License
    MIT License
  • Created over 6 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Ethereum utilities for Elixir

Hex Version Hex docs

ETH

The essential Elixir library for interacting with Ethereum blockchain. You can now create Ethereum wallets, query the blockchain and sign/send transactions, all from Elixir / Erlang Virtual Machine.

Example

  wallet = ETH.Wallet.create
  # %{eth_address: "0x31CF67A272A23C7A11128C97FC3B2F4C13AFD87F",
  #   mnemonic_phrase: "similar bleak naive absorb picnic avoid sponsor canoe inform misery crisp hotel critic have parent couch wrong survey staff primary wet wear velvet horse",
  #   private_key: "C8E2F24A806A422034990C7391B4CEB7133CD3680987FEBB5750555F99F0FC83",
  #   public_key: "04C4AA07F234226CA90FB3E8BB1590D5BEB703E449700FE0B2DF539A948289EA75220CC837CA68F429F3FB3D6677B2D63CF66277888B8209D0B3F3229CE339654C"}

  specific_private_key = "9756371A51D7FC25EDFC95A49DEF3806ED34DF2EBCA2065E543369E708C47374"
  another_wallet = ETH.Wallet.create(specific_private_key)
  # %{eth_address: "0x6A26B49D8046DC5B74D41E29F9A5CA7AD78EEC9B",
  #   mnemonic_phrase: "nuclear random shoot photo lemon base retire naive pig urge sock assist spy hurdle road nephew alien verify art stable identify giraffe soccer mushroom",
  #   private_key: "9756371A51D7FC25EDFC95A49DEF3806ED34DF2EBCA2065E543369E708C47374",
  #   public_key: "04D1F70F6048D1E22FBEBBF3AF462E3356747AB2BB81EC269C600BE6A53C3223472AA336DF0060719C6F3AEC45E40AE57ED39735B61B8F5EF989466D46CA1B72C0"}

  accounts_in_your_client = ETH.get_accounts
  # ["0xfdf5d02f2082753dda0817492d6efff7e76e47aa",
  #  "0xb9906b679aa8edd03fdf7fe396af4d9a77af4108",
  #  "0xae6463bf32efc106ad4300d902e572e1c43e6e9c",
  #  "0xb764c82ae23467be2cf90ab9019ee2464a3946f9",
  #  "0xfc5b5a6cd171f4123439f28fad9986c70572b35f",
  #  "0x7605c8812cfb51a7d2d16e598f521c9302d0ed7f",
  #  "0x7dab29cc88c2ecd69ec216b7d089a82bb95fe1ad",
  #  "0xba3a30f3c4fd2b4a44936b42ceea87ec3e53294a",
  #  "0xb3f4869ce14d6bbd659dc5d2f9a515b58b2765d2",
  #  "0x8c9cec7feacdbbf472ebcc4f61224d83c880896b"]

  first_account_in_your_client = List.first(accounts_in_your_client)
  first_account_private_key = "f121f608500f7e3379c813aa6df62864e35aa0b6cd11a2ff2c20ac84b5771fb2"

  ETH.get_balance("0x31CF67A272A23C7A11128C97FC3B2F4C13AFD87F") # {:ok, 0} # this account holds no ether
  ETH.get_balance!(first_account_in_your_client, :wei) # 1.0e20 -> in this example this address holds 100 ether / 1.0e20 wei

  ETH.get_transaction_count(first_account_in_your_client) # {:ok, 0}

  {:ok, tx_hash} = ETH.send_transaction(%{
    from: first_account_in_your_client, to: wallet[:eth_address], value: 22
  }, first_account_private_key)
  # {:ok, "0x13893d677251ddb9259263490504f3e611a0a7bff23b108641d2cb08b7af21dc"}

  ETH.get_transaction!(tx_hash)
  # %{block_hash: "0xf9917088fc6750677cc1cfb4f7dcab453b21c7de2cb22ed7e6753df058bec5cf",
  #   block_number: 1, from: "0xfdf5d02f2082753dda0817492d6efff7e76e47aa",
  #   gas: 21000, gas_price: 20000000000,
  #   hash: "0x13893d677251ddb9259263490504f3e611a0a7bff23b108641d2cb08b7af21dc",
  #   input: "0", nonce: 0, to: "0x725316bb37d202b0eb203cd83238c31e983a7936",
  #   transaction_index: 0, value: 22}

  ETH.get_balance!(first_account_in_your_client) # 99.99958 # in ether
  ETH.get_balance(wallet[:eth_address], :wei) # {:ok, 22.0} # in wei

Warning: This library uses the Ethereum JSON-RPC under the hood, so you need an ethereum client such as parity/geth or testrpc to use of most of the API.

Credits

  • Izel Nakri - I reverse engineered ethereum JavaScript libraries in Elixir so you don't have to.

Additionally this library wouldnt exist without the libraries below:

  • ExRLP
  • Ethereumex
  • keccakf1600
  • libsecp256k1

NOTE:

To properly use this package, you will need to run rebar compile eunit for libsecp256k1.

TODO:

Ethereum Smart Contracts, small enhancements

Installation

If available in Hex, the package can be installed by adding eth to your list of dependencies in mix.exs:

def deps do
  [
    {:eth, "~> 0.6.5"}
  ]
end

Running the tests

Install a testrpc(now renamed to ganache) to run ethereum locally: npm install -g ganache

Elixir tests automatically spawns and kills the ganache process. All you need to do now is to run the tests in sequence thus --seed 0: mix test --seed 0

The docs can be found at https://hexdocs.pm/eth.

More Repositories

1

paper_trail

Track and record all the changes in your database with Ecto. Revert back to anytime in history.
Elixir
539
star
2

express-routemap

Display all your express routes in the terminal!
JavaScript
132
star
3

mber

Fast and minimal Ember.js CLI alternative, without broccoli.
JavaScript
32
star
4

qunitx

Only JS/TS universal automated testing framework for any JavaScript/TypeScript runtime(s)
JavaScript
31
star
5

memoria

Single JS/TS ORM for frontend, backend & in-memory testing. Based on typeorm API, allows you to change adapters: MemoryAdapter, RESTAdapter, SQLAdapter etc.
TypeScript
17
star
6

mnemonic

Elixir library for generating deterministic private keys from words according to BIP39 standard.
Elixir
17
star
7

emberx

Ember like router and libraries for glimmer.js
TypeScript
10
star
8

memserver

JS http mock server AND ORM/in-memory/in-js-vm DB you can run in-browser and node environments. Extremely useful library for fast frontend tests, rapid prototyping and single-file SPA demo deployments.
JavaScript
7
star
9

aes256

AES256 implementation in Elixir
Elixir
7
star
10

glimmer-embedded

Experimenting with glimmer-vm
JavaScript
5
star
11

mirage-glue

Mirage Fixtures > Factories for deterministic tests. This program reads your API endpoint and creates or appends response to relevant mirage fixture file(s).
JavaScript
4
star
12

mber-rust

Rust port of mber
Rust
4
star
13

nvim

my made-to-measure nvim config
Vim Script
3
star
14

qunitx-cli

CI browser runner for qunitx test framework
JavaScript
3
star
15

recursive-lookup

Dependency-free and fast async recursive fs lookups in node.js
JavaScript
2
star
16

riotjs-redux-experiment

Over-engineered to the max repo with lots of experiments
JavaScript
2
star
17

helman

Kubernetes Helm <> Kustomize bridge
JavaScript
1
star
18

nycda-backend-exam

1
star
19

nycda-chat-app

JavaScript
1
star
20

concurrent-elixir-examples

From Programming Elixir 1.2
Elixir
1
star
21

.dotfiles

Shell
1
star
22

fixturist

Fix the foreign-key constraints in your fixture driven backend tests. This library is an algorithm for populating relationships from your development database
Elixir
1
star
23

browser-inputs

fast and mature user input helpers for qunit, extracted from ember
TypeScript
1
star
24

github-issues-tracker-elixir

Taken from Programming Elixir 1.2
Elixir
1
star
25

moses

one <script> tag that turns your frontend framework into a styleguide:
CSS
1
star
26

mber-head

ember-cli-head fork that supports module unification for mber
JavaScript
1
star