JS SDK
Data Engine's live data feeds can be accessed through the Relayer using the official JS SDK.
Last updated
Data Engine's live data feeds can be accessed through the Relayer using the official JS SDK.
Last updated
The general process to set-up and other do's & don'ts while connecting to the relayer remain the same as discussed in the WebSockets section.
You can connect to the Relayer using the JS-SDK across 2 platforms - the browser (web) & node.js (server-side). The SDK allows you to seamlessly use it across both the codebases without any changes and do so with full-type safety by TypeScript Support.
The SDK is available to install in your applications using your favorite package manager. It is currently published on . This is the easiest way to install the SDK if you're using a modern web framework like Next.js, React or Astro. Or if you're using any runtime like Node.js, Bun etc.
The SDK can also be installed in your project even when you're not using a package manager. To add the SDK to your frontend you can use a popular CDN to deliver the minified SDK on the edge.
Firstly, set-up your imports and initialize the SDK with the appropriate feedIDs.
Then, add event listeners to receive the relevant events related to the connection you've just set-up.
The SDK supports the following events for which you can add relevant event listeners -
open
: Event is initiated whenever the Relayer connection is started.
close
: Event is initiated whenever the Relayer connection is closed.
Now, that you've set-up everything. We can start the connection with an appropriate deadline and fetch the data feeds.
data
: Receives the data events for all the data feeds that you've initially subscribed to in the form of .
info
: Receives the connection related info messages like among others.