Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

state_subscribeStorage - Avail

Example code for the state_subscribeStorage WebSocket method. Complete guide on how to use state_subscribeStorage WebSocket in GetBlock Web3 documentation.

Opens a subscription that streams change sets whenever any of the given storage keys change. WebSocket only. Passing an empty key list subscribes to all storage changes (heavy).

Parameters

Parameter
Type
Required
Description

keys

array

Yes

Array of hex storage keys to watch

Subscribe

wscat -c wss://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/

# then send:
{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "method": "state_subscribeStorage",
    "params": [
        [
            "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9"
        ]
    ]
}

Subscription ID

The initial response returns the subscription id used to correlate and cancel the stream:

Notifications

While subscribed, the node pushes a notification per update:

Notification Fields

Field
Type
Description

block

string

Block at which the change occurred

changes

array

Array of [key, value] change pairs; value null if cleared

Use Cases

  • Balance Watching: React to account balance changes

  • Live State: Keep a cache in sync with on-chain storage

  • Event-Driven UIs: Update views on state changes

Error Handling

Error
Message
Description

-32603 / Internal error

Subscription error

The subscription could not be established

403 / RBAC: access denied

Access denied

The GetBlock access token is missing or incorrect

Last updated

Was this helpful?