> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chainstack.com/llms.txt
> Use this file to discover all available pages before exploring further.

# clearSubscriptions | Arbitrum

> Use eth_clearSubscriptions on Arbitrum via ethers.js to remove all active WebSocket subscriptions from your Chainstack node connection at once.

The subscriptions available using the ethers.js `provider.on` method are:

> [card] [on('block')](https://docs.chainstack.com/reference/arbitrum-subscribenewblockheaders.md)

> [card] [on(filter)](https://docs.chainstack.com/reference/arbitrum-subscribelogs.md)

> [card] [syncing subscription](https://docs.chainstack.com/reference/arbitrum-subscribesyncing.md)

## Parameters

`boolean` — keep the [syncing subscription](https://docs.chainstack.com/reference/arbitrum-subscribesyncing.md) if `true`.

## Response

`boolean` — the boolean value indicating if the subscriptions were removed successfully. `true` if removed successfully, `false` if not.

## `clearSubscriptions` code example

```javascript index.js theme={"system"}
const { ethers } = require("ethers");
const NODE_URL = "CHAINSTACK_WSS_URL";
const provider = new ethers.WebSocketProvider(NODE_URL);

async function clearSubscriptions() {
    try {
      await provider.removeAllListeners();
      console.log("Subscriptions were canceled successfully");
      return process.exit(1)

    } catch (error) {
      console.error("Failed to cancel subscriptions:", error);
      return process.exit(1)
    }
  }

clearSubscriptions()
```

## Use case

A 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 [block subscription](https://docs.chainstack.com/reference/arbitrum-subscribenewblockheaders.md), which will be stopped and removed after one minute using `removeAllListeners`:

```javascript index.js theme={"system"}
const { ethers } = require("ethers");
const NODE_URL = "CHAINSTACK_WSS_URL";
const provider = new ethers.WebSocketProvider(NODE_URL);

async function subscribeToNewBlocks() {
    try {
        // Log a message when the block subscription is set up
        handleConnected();

        // Subscribe to new blocks and attach event listeners
        provider.on("block", handleNewBlock);
        provider.on("error", handleError);
    } catch (error) {
        console.error(`Error subscribing to new blocks: ${error}`);
    }
}

/* Fallback functions to react to the different events */

// Function that logs a message when the subscription is connected
function handleConnected() {
    console.log("New subscription to new blocks");
}

// Event listener that logs the received block data
async function handleNewBlock(blockNumber) {
    const block = await provider.getBlock(blockNumber);
    console.log(block);
}

// Event listener that logs any errors that occur
function handleError(error) {
    console.error(`Error receiving new blocks: ${error}`);
}

async function clearSubscriptions() {
    try {
        await provider.removeAllListeners();
        console.log("Subscriptions were canceled successfully");
        return process.exit(1)

    } catch (error) {
        console.error("Failed to cancel subscriptions:", error);
        return process.exit(1)
    }
}

async function main() {

    subscribeToNewBlocks();

    // Run clearSubscriptions() once after 60 seconds
    setTimeout(clearSubscriptions, 60000);
}

main()
```

The code starts by defining an async function called `subscribeToNewBlocks` that subscribes to new blocks using the `provider.on("block")` method. This method registers a listener that fires on every new block, and the code also attaches a listener for the `error` event. The code defines three functions `handleConnected`, `handleNewBlock`, and `handleError` that log messages to the console when the subscription is set up, when a new block arrives, and when an error occurs.

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 `provider.removeAllListeners` method to cancel any existing subscriptions and log a message to the console if the cancellation was successful.
