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. ![]()
First Post!
julismz
Is this project/lib alive? The last commit is from a year ago…
Popular in Announcing
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...
New
Hi everyone,
We would like to announce that Plataformatec is working on a new MySQL driver called MyXQL. Our goal is to eventually integ...
New
Let’s write a database! Well not really, but I think it’s a little sad that there doesn’t seem to be a simple in-memory distributed KV da...
New
I’ve just released stable versions of my Prometheus Elixir libs:
Elixir client [docs];
Ecto collector [docs];
Plugs instrumenter/Export...
New
Hi, I wanted share a small library we at Revelry Labs made for rendering react components from the server side. There are instructions fo...
New
Hey everyone
i’ve developed a library for Jalaali calendar for elixir which supports converting Gregorian dates to Jalaali and vice vers...
New
The best overview for how things are tied together is this presentation. Modules and functions are pretty well documented at this point, ...
New
It is a well-know topic within the Elixir community: “To mock or not to mock? :)”
Every alchemist probably has his / her own opinion con...
New
TypeCheck: Fast and flexible runtime type-checking for your Elixir projects.
Core ideas
Type- and function specifications are const...
New
Hey all,
We have made an Ecto3 Adapter for SQLite3, ecto_sqlite3!
We have successfully on-boarded the full suite of integration tests (...
New
Other popular topics
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help.
Where are they similar?
Where do they differ the m...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
In templates/appointment/index.html.eex:
<%= for appointment <- @appointments do %>
<tr>
<td><%= appoi...
New
Hello guys,
I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
Hi!
Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








