At Nodesmith, we’re making interacting with Ethereum via the JSON RPC API as simple, reliable, and performant as possible. To meet those goals, our initial beta offered stateless access via HTTP only. This meant we were missing two key tools for developers: 1) WebSocket support, including subscriptions which allow you to get changes pushed to you in realtime, and 2) the creation of filters, which can be polled periodically to see state changes.

Today — we’re happy to announce that we’ve released support for both! If you want to jump straight into it — check out our quick start documentation.

We’ve experienced frustration in the past with the reliability of WebSockets while using local nodes or various node provider alternatives. Driven by that, we’ve architected our solution to ensure the WebSockets connections developers make are incredibly stable — all while using the same JSON RPC interfaces that you’re accustomed to.

WebSockets

Developers using Nodesmith can now access each JSON RPC method over WSS in addition to over HTTP. This means you can now use Nodesmith as a WebSocket provider with your favorite client library.

Creating a WebSocket subscription with web3.js

But where WebSockets really shine is in the ability to support subscriptions. WebSockets provide bi-directional communication between a client and the Ethereum Network via Nodesmith. Instead of requiring a client to periodically query to see if anything has changed, WebSockets allow clients to have data pushed to them when changes occur.

To enable this, Nodesmith now supports the eth_subscribe & eth_unsubscribe methods. These methods are part of the RPC pub/sub module, and allow for the following notifications:

New Blocks - Each time a new block is added to the chain, a notification is sent with info about that new block. If a re-org happens, all the blocks which are part of the reorg will be included as well.

Each time a new block is added to the chain, a notification is sent with info about that new block. If a re-org happens, all the blocks which are part of the reorg will be included as well. New Logs - Notifies whenever a new block includes a log which matches the filter you specify is mined. This is a great way to watch for specific events in your smart contract (see example below)

- Notifies whenever a new block includes a log which matches the filter you specify is mined. This is a great way to watch for specific events in your smart contract (see example below) New Pending Transaction Receive a notification whenever someone submits a new pending transaction to the network

Here’s a concrete example — this Code snippet below uses a WebSockets subscription to get notified anytime a log matching the Transfer Event is emitted by any contract address on the network. This means anytime a token is transferred, a new line shows up in the table.