stocks29
W3WS
Ethereum websocket library for Elixir
Features
W3WS.Listenerfor listening to new eventsW3WS.Replayerfor replaying events from past blocksW3WS.Rpcfor 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.
Trending in Announcing
Hey everyone!
Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application.
This library uses Erlang esaml to provide
plug enabl...
New
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries.
offset-based pagination with...
New
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
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi all!
I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas.
You...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
This showed up on my feed.. anyone heard of it? Just hype?
Ox Alpha is a reasoning model designed for coding, sustained ag...
New
It’s not that it’s vocabulary is too advanced. It’s something worse.
I get lost trying to follow even a paragraph written by Claude. It’...
New
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New
Introductory paragraph
I’ll be looking for a keen junior or someone that has a couple of years experience in the real world (so you’ve be...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
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/1kept returning empty listI could make it work by adding some little tweak:
I used hardhat with
pragma solidity ^0.8.0versiondarkblueorange
Now I’m stuck on a weird network authentication-like error:
I cannot see in your docs any distant URL to test, so maybe I’m not using the library as intended.
The same configuration works in JS with ethers.js though, and I don’t need any API key to listen to pubsub events.
I hope you have an idea of what’s going on, I would really be happy to have a steady websocket listening to the blockchain.
EDIT
Well, I was too hasty saying I had no APP key.
My Alchemy URL actually contains it:
wss://eth-sepolia.g.alchemy.com/v2/<APP_KEY>And apparently
URI.new!/1truncates it in your__using__macro inside@behaviour W3WS.RpcBase(rpc_base.ex)The guilty is there:
when I manually add a correct :path key containing my APP key inside this function it does seem to work (no error logs).
EDIT bis
The mistake was on my side !! forget this post please

I keep digging into the docs for now
darkblueorange
So I continued to use the library.
TLDR: it crashes in almost all places if networks is lost (because of
Windlack of error handling).It seems to work globally fine, except when network is lost.
I spelunked a bit and arrived to this understanding:
Underlying
Mintlibrary raises, butWindwrapper does not handle it properly.In wind
client.ex(ModuleWind.Client)handle_info/2receives 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/4function ofWindModule 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/2first, but if we fix it,Wind.Client.handle_info/2will also crash), the associated GenServer reboots and attempts to launch a new connection throughhandle_continue/2inWind.ClientModule.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
pingspaced 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
stocks29
Thanks for trying out W3WS and providing feedback!
I’m using
"hardhat-abi-exporter": "^2.10.1",to export the ABI for my projects. This seems to be a standard format which JS libraries understand. I’d be interested to understand what ABI format you’re using. Would you mind sharing an example?Regarding the crashing, I think this is something that should be handled at the
ListenerManager(supervisor) level, since if the network is gone there is nothing theListenercan do. We could add an optionaloptskeyword list which would be passed toDynamicSupervisor.start_link/2allowing you to pass:max_restartsand:max_seconds. This is the block of code I’m referring to:This would enable you to allow more time for the network to come back. Of course if the network never comes back the app is still going to crash. Would you want to give this a try and see if it suites your needs?
darkblueorange
Thanks a lot for the very quick reply
Well I’m a real beginner in Blockchain dev.
I didn’t use any external library, I naively retrieved the JSON produced by
npx hardhat compile, underartifact/contracts/MyContract.sol/MyContract.jsonI see that the output is really similar:
only a key dive away (“abi”) to get the same thing.
Regarding the network crashing, I’m not sure handling blockchain network availability by hoping that a crash or a change in it (node adress, alchemy account, anything) would just be temporary is the way I would like to go.
).
My whole application is not only about blockchain interactions, so seing it totally crash because of a blockchain network issue makes it too dependant.
I read in the meantime about GenServers, and the philosophy I got was that restarts are not a design pattern, but an exception.
I raised an issue in Wind github, as I believed it should be handled there (I may be mistaken
stocks29
Thanks for opening the wind ticket. I agree that crashing the entire app is not ideal in this case.
It would be great if Wind could re-connect when the network issue is resolved. I do worry about it failing silently forever though.
Another option would be some sort of supervisor that tries to restart the worker forever without failing. I’m not sure if something like this exists. Potentially the same problem with failing silently forever though.
All that said, I’m yet to have any issues with alchemy. Their reliability has been great so far. Although something could definitely break between your instance and their API.
On a security note, you may want to remove your alchemy API key from this comment: Crash when network is lost · Issue #3 · bfolkens/wind · GitHub