Gnosis Chain web3.js method used to unsubscribe from all subscriptions made with the web3.eth.subscribe
method. This method is useful for removing all of the subscriptions at once.
The subscriptions available using the web3.eth.subscribe
methods are:
Start for free and get your app to production levels immediately. No credit card required.
You can sign up with your GitHub, X, Google, or Microsoft account.
boolean
— keep the subscribe(“syncing”) subscription if true
.
boolean
— the boolean value indicating if the subscriptions were removed successfully. true
if removed successfully, false
if not.
clearSubscriptions
code exampleA way to use the clearSubscriptions
method is to place it in a timer to clear all of the subscriptions after a pre-determined about.
The following code is an example using the subscribe(“newBlockHeaders”) method, which will be stopped and removed after one minute using clearSubscriptions
:
The code starts by defining an async function called subscribeToNewBlocks
that creates a new subscription to the newBlockHeaders
event using the web3.eth.subscribe
method. This method returns a subscription object that can be used to attach event listeners for different events, such as connected
, data
, and error
. The code defines three event listener functions handleConnected
, handleNewBlock
, and handleError
that log messages to the console when these events occur.
The subscribeToNewBlocks
function is called from the main
function, which is also defined in the code. The main
function calls subscribeToNewBlocks
to create a new subscription and then schedules the clearSubscriptions
function to run once after 60 seconds using the setTimeout
function. The clearSubscriptions
function uses the web3.eth.clearSubscriptions
method to cancel any existing subscriptions and log a message to the console if the cancellation was successful.
Gnosis Chain web3.js method used to unsubscribe from all subscriptions made with the web3.eth.subscribe
method. This method is useful for removing all of the subscriptions at once.
The subscriptions available using the web3.eth.subscribe
methods are:
Start for free and get your app to production levels immediately. No credit card required.
You can sign up with your GitHub, X, Google, or Microsoft account.
boolean
— keep the subscribe(“syncing”) subscription if true
.
boolean
— the boolean value indicating if the subscriptions were removed successfully. true
if removed successfully, false
if not.
clearSubscriptions
code exampleA way to use the clearSubscriptions
method is to place it in a timer to clear all of the subscriptions after a pre-determined about.
The following code is an example using the subscribe(“newBlockHeaders”) method, which will be stopped and removed after one minute using clearSubscriptions
:
The code starts by defining an async function called subscribeToNewBlocks
that creates a new subscription to the newBlockHeaders
event using the web3.eth.subscribe
method. This method returns a subscription object that can be used to attach event listeners for different events, such as connected
, data
, and error
. The code defines three event listener functions handleConnected
, handleNewBlock
, and handleError
that log messages to the console when these events occur.
The subscribeToNewBlocks
function is called from the main
function, which is also defined in the code. The main
function calls subscribeToNewBlocks
to create a new subscription and then schedules the clearSubscriptions
function to run once after 60 seconds using the setTimeout
function. The clearSubscriptions
function uses the web3.eth.clearSubscriptions
method to cancel any existing subscriptions and log a message to the console if the cancellation was successful.