WebSockets

This tutorial introduces how to subscribe and unsubscribe websockets. The article will use eth-mainnet as an example, and if you want to switch to another network, simply replace the path with the endpoint of the network.

The supported networks for the Endpoint(wss): wss://{chain-network}.4everland.org/ws/v1/{apikey} are as follows:

Chain Full Name
Chain
Network

BNB Smart Chain

bsc

mainnet; testnet;

opBNB

opbnb

mainnet; testnet;

Ethereum

eth

mainnet; testnet; //goerli

Optimism

opt

mainnet;

Polygon

polygon

mainnet;

eth_subscribe-eth

Parameters

  • SUBSCRIPTION TYPE NAME [required]

    • newHeads- To receive a notification each time a new header is appended to the chain

    • logs - Returns logs that are included in new imported blocks and match the given filter criteria.

      • address (optional) - either an address or an array of addresses

      • topics (optional) - only logs which match the specified topics

    • newPendingTransactions - Returns the hash for all transactions that are added to the pending state and are signed with a key that is available in the node

    • syncing - Indicates when the node starts or stops synchronizing.

Returns

  • SUBSCRIPTION ID - ID of the newly created subscription on the node

Examples

check out the example below:

Request

Result

eth_unsubscribe-eth

Parameters

  • SUBSCRIPTION ID

Returns

  • boolean, true if the subscription was cancelled successfully.

Example

check out the example below:

Request

Result

If you have any questions, please join our Discord server, or send us an email at [email protected].

Last updated