stocks29

stocks29

W3WS - Ethereum websocket library for Elixir

W3WS

Ethereum websocket library for Elixir

Features

  • W3WS.Listener for listening to new events
  • W3WS.Replayer for replaying events from past blocks
  • W3WS.Rpc for sending messages and receiving responses over the websocket with both sync and async interfaces.

Links

Notes

The library is still in the early stages. Feedback and suggestions are welcome.

Most Liked

darkblueorange

darkblueorange

Thanks for this library!

I gave it a try and had some trouble parsing the contract.
It seems like I didn’t have the same ABI encoding
W3WS.ABI.from_files/1 kept returning empty list

I could make it work by adding some little tweak:

def from_files(paths) do
    Enum.flat_map(paths, fn path ->
      json_abi = path
      |> File.read!()
      |> Jason.decode!()

      json_abi
      |> Map.has_key?("abi")
      |> case do
        true ->
          resolve_bad_list(json_abi["abi"])
        _ ->
          ABI.parse_specification(json_abi, include_events?: true)
      end
      |> filter_abi_events()
    end)
  end

  defp resolve_bad_list(abi) do
    abi
    |> Enum.reduce([], fn elem, acc ->
      [parsed] = ABI.parse_specification([elem], include_events?: true)
      [parsed | acc]
    end)
  end

I used hardhat with pragma solidity ^0.8.0 version

darkblueorange

darkblueorange

So I continued to use the library.

TLDR: it crashes in almost all places if networks is lost (because of Wind lack of error handling).

It seems to work globally fine, except when network is lost.
I spelunked a bit and arrived to this understanding:
Underlying Mint library raises, but Wind wrapper does not handle it properly.

In wind client.ex (Module Wind.Client) handle_info/2 receives a damaged state (disconnected or closed) and fails in handling the error on this line:
{:ok, conn, websocket, data} = Wind.decode(conn, ref, websocket, message)
(it was quite hard for me to debug, I couldn’t find some simple/working way to decompile Elixir .beam files to find the proper line failing at first, with all the macros and using_ all over the place)

If we go to the decode/4 function of Wind Module we can see another failing error handling case:
with {:ok, conn, [{:data, ^ref, data}]} <- Mint.WebSocket.stream(conn, message), ... do ...
(no else, and this is actually the first place failing)

Besides when this function crashes (Wind.decode/2 first, but if we fix it, Wind.Client.handle_info/2 will also crash), the associated GenServer reboots and attempts to launch a new connection through handle_continue/2 in Wind.Client Module.
Of course network is still down, so here is another fail (the infamous :nxdomain), and we end up in sending {:stop, {:error, conn, reason}, state} to the GenServer.
It could be good to fail (I would personally have preferred a ping spaced more and more to attempt after n*i seconds with i growing over time), but the thing is that when the GenServer stops it crashes the whole application.
Maybe here you can do something to avoid this?
I’m not familiar with all the GenServer communication and possible events handling (maybe using Process.send_after(self(), ... is a way), so I could not propose some PR in a reasonable time.

Bug is easy to reproduce, just switch off your wifi, or close your laptop for a minute :slight_smile:

Where Next?

Popular in Announcing Top

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 29377 241
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
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 42920 311
New
jakub-zawislak
Hi everyone, I’m coming from the Symfony (PHP) framework. I like Phoenix, but it has a one thing that was build much better in the Symfo...
New
josevalim
Yes, yet another parser combinator library! Most of the parser combinators in the ecosystem are either compile-time, often using AST tra...
159 19228 141
New
josevalim
EDIT: since Ecto 3.0 final version is out, this post was amended to use the final versions in the instructions below. Hi everyone, We a...
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
bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
384 13736 119
New
kip
Image is an image processing library for Elixir. It is based upon the fabulous vix library that provides a libvips wrapper for Elixir. I...
622 18474 194
New
Qqwy
Hello everyone, I wrote a small library today called MapDiff. It returns a map listing the (smallest amount of) changes to get from map...
New

Other popular topics Top

AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
aesmail
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
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39297 209
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement