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:
BNB Smart Chain
bsc
mainnet; testnet;
opBNB
opbnb
mainnet; testnet;
Ethereum
eth
mainnet; testnet; //goerli
Optimism
opt
mainnet;
Polygon
polygon
mainnet;
eth_subscribe-eth
eth_subscribe-ethParameters
SUBSCRIPTION TYPE NAME[required]newHeads- To receive a notification each time a new header is appended to the chainlogs- Returns logs that are included in new imported blocks and match the given filter criteria.address(optional) - either an address or an array of addressestopics(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 nodesyncing- 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
eth_unsubscribe-ethParameters
SUBSCRIPTION ID
Returns
boolean, true if the subscription was cancelled successfully.
Example
check out the example below:
Request
Result
Last updated