zven21

zven21

Web3 - High level, user-friendly Ethereum JSON-RPC Client

Web3 It’s a high level, user-friendly and support middleware Ethereum JSON-RPC Client.

Features

  • Ethereum JSON-RPC Client
  • Interacting smart contracts
  • Querying past events
  • Event monitoring as Streams
  • Websockets

Example 1

# Defining the application
defmodule MyApp.Application do
  use Web3, rpc_endpoint: "<PATH_TO_RPC_ENDPOINT>"

  # middleware (optional)
  middleware MyApp.Middleware.Logger

  # dispatch (optional)
  dispatch :eth_getBalance, args: 2

  # contract (optinnal)
  contract :FirstContract, contract_address: "0xdAC17F958D2ee523a2206206994597C13D831ec7", abi_path: "path_to_abi.json"
end

# (Optional) If you need to customise your middleware.
defmodule MyApp.Middleware.Logger do
  @moduledoc false

  @behaviour Web3.Middleware

  require Logger
  alias Web3.Middleware.Pipeline
  import Pipeline

  @doc "Before Request HTTP JSON RPC"
  def before_dispatch(%Pipeline{} = pipeline) do
    # Set metadata assigns here.
    Logger.info("MyApp before_dispatch")
    pipeline
  end

  @doc "After Request HTTP JSON RPC"
  def after_dispatch(%Pipeline{} = pipeline) do
    Logger.info("MyApp after_dispatch")
    pipeline
  end

  @doc "When after request HTTP JSON RPC failed"
  def after_failure(%Pipeline{} = pipeline) do
    Logger.info("MyApp after_failure")
    pipeline
  end
end

# Get latest block number
iex> MyApp.Application.eth_blockNumber
{:ok, 15034908}

# Get address balance.
iex> MyApp.Application.eth_getBalance("0xF4986360a6d873ea02F79eC3913be6845e0308A4", "latest")
{:ok, 0}

# Get multi-addresses balance.
iex> MyApp.Application.eth_getBalance(["0xF4986360a6d873ea02F79eC3913be6845e0308A4", "0xF4986360a6d873ea02F79eC3913be6845e0308A4"], "latest")
{:ok,
  %{
    errors: [],
    params: ["0xF4986360a6d873ea02F79eC3913be6845e0308A4", "0xF4986360a6d873ea02F79eC3913be6845e0308A4"],
    result: [0, 0]
  }
}

# Query Contract
iex> MyApp.Application.FirstContract.balanceOf_address_("0xF4986360a6d873ea02F79eC3913be6845e0308A4")
{:ok, 0}

# Make Transaction
iex> MyApp.Application.FirstContract.approve_address_uint256_(
  "0x0000000000000000000000000000000000000000",
  10,
  gas_price: 12_000_000_000,
  gas_limit: 300_000,
  chain_id: 1,
  nonce: 1,
  priv_key: "xxxxxxxxxxxxxxxxxxxxxxxxx"
)

{:ok, true}

More information on web3.

Thank you for reading, have a good day. :smile:

First Post!

julismz

julismz

Is this project/lib alive? The last commit is from a year ago…

Where Next?

Popular in Libraries Top

mbuhot
Leverage Open Api 3.0 (Swagger) to document, test, validate and explore your Plug and Phoenix APIs. Generate and serve a JSON Open API ...
New
tmbb
I’ve published the first version of my Makeup library. It’s a syntax highlighter for Elixir in the spirit of Pygments, Currently it highl...
New
Crowdhailer
I have been updating a library that allows you to pipe between functions that use the erlang result tuple convention. Assuming you have...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
martinthenth
Hello everybody :wave: Recently, some of my colleagues talked about database ids and uuids and their problems, and I remembered the pain...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
tmbb
PhoenixWS - Websockets over Phoenix Channels Source code on Github here: https://github.com/tmbb/phoenix_ws Phoenix channels are a great...
New
gabrielpoca
Hello everyone! I want to share with you something that I’m really proud of: https://stillstatic.io/ Still is a static site builder for...
New
mtrudel
Bandit is an HTTP server for Plug and WebSock apps. Bandit is written entirely in Elixir and is built atop Thousand Island. It can serve...
New
Azolo
Hey everyone, I just released WebSockex which is a Elixir WebSocket client. WebSockex strives to work as a OTP special process, be RFC6...
New

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
sergio
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Sub Categories:

We're in Beta

About us Mission Statement