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 Libraries
https://www.conduitframework.com/
The best overview for how things are tied together is this presentation. Modules and functions are pre...
New
Lexical
Lexical is a next-generation language server for the Elixir programming language.
Features
Context aware code completion
As-you...
New
Hi everyone,
I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
New
What is ContEx?
A pure Elixir server-side data plotting/charting library outputting SVG.
It has nice barcharts in particular and works g...
New
Hello there,
I would like to share a feature toggles library (AKA feature flags) I’ve been working on.
The main package is FunWithFlags...
New
Dear Elixir community,
After a year of development, bug fixes, and improvements, we are proudly ready to share the release of Crawly 0.1...
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
Hi!
I wanted to introduce my latest project LiveSvelte. It allows you to render Svelte inside LiveView with end-to-end reactivity. It’s ...
New
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
simple_feature_flags is a tiny package that lets you turn features on or off based on which environment (e.g. localhost, staging, product...
New
Other popular topics
Hi! May someone helps me, please!
I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
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
Good day to you all.
I have been struggling to get a query involving like and ilike to work.
Can anyone assist me on this, please?
pro...
New
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
Hello,
I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these
buyer = %{
id: ...
New
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this
"1000"
What is the ...
New
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
As a follow up to my earlier question:
I have the code compiling and running but not getting a successful login from the rest server. ...
New







