Subscribe to Events
Event Subscription is used to subscribe to specific events or transactions occurring within a blockchain network. It enables participants to get updates or notifications in real time whenever a specific event happens.
Following are the event subscriptions that a user can subscribe to-
WETH
ERC-20
ERC-721
ERC-1155
Streaming Events:
Users can stream events in two ways:
Example 1: via wscat script (For Linux based distro)
First, the user needs to run the following command in their terminal to install wscat in their system:
npm install -g wscat After installing wscat, the user needs to create a shell script and paste the following sample code:
Client Side Sample Socket Code :
#!/bin/bash
echo "Price Discovery\n"
read -p "x-api-key: " YOUR_API_KEY
wscat -c wss://pricediscovery.expand.network -H authorization:secret-token -H x-api-key:$YOUR_API_KEYAfter following the above steps, the user needs to run the file. This can be done by entering the filename in the console.
Executing a query:
After executing the aforementioned file(shell script), the user will be prompted to input the appropriate API key.
After entering the API key, the user can subscribe to the following actions:
Applying a filter in the query:
Users can apply the following filters in their query:-
WETH
The above filters can be applied in any combination, using the following syntax:
Sample Query:
Example 2. via javascript code
First, the user needs to run the following command in their terminal to install wscat in their system:
After installing ws, the user needs to run the following sample code on their device to start streaming:
Client Side Sample Socket Code :
Expected Output:
ERC-20
The above filters can be applied in any combination, using the following syntax:
Sample Query:
Example 2. via javascript code
First, the user needs to run the following command in their terminal to install wscat in their system:
After installing ws, the user needs to run the following sample code on their device to start streaming:
Client Side Sample Socket Code :
Expected Output:
ERC-721
The above filters can be applied in any combination, using the following syntax:
Sample Query:
Example 2. via javascript code
First, the user needs to run the following command in their terminal to install wscat in their system:
After installing ws, the user needs to run the following sample code on their device to start streaming:
Client Side Sample Socket Code :
Expected Output:
ERC-1155
The above filters can be applied in any combination, using the following syntax:
Sample Query:
Example 2. via javascript code
First, the user needs to run the following command in their terminal to install wscat in their system:
After installing ws, the user needs to run the following sample code on their device to start streaming:
Client Side Sample Socket Code :
Expected Output:
How to disconnect:
To disconnect from our API, enter ctrl-c in the connected console.
Last updated

