state_subscribeStorage - Bittensor RPC Method
Subscribe to real-time storage changes for specific keys via WebSocket on Bittensor.
Subscribes to storage changes for a set of keys via a WebSocket connection. Each time one or more of the specified keys change in a new block, a notification is emitted with the updated values. This enables real-time reactive applications that respond to on-chain state changes without polling.
The initial JSON-RPC response returns a subscription ID. Storage-change payloads are delivered afterward as WebSocket notifications for that subscription.
Code Examples
This method requires a WebSocket connection and is not available over HTTP.
WebSocket (wscat)
wscat -c wss://api-bittensor-mainnet.n.dwellir.com/YOUR_API_KEY \
-x '{
"jsonrpc": "2.0",
"method": "state_subscribeStorage",
"params": [
["0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9"]
],
"id": 1
}'JavaScript
import { ApiPromise, WsProvider } from '@polkadot/api';
const api = await ApiPromise.create({
provider: new WsProvider('wss://api-bittensor-mainnet.n.dwellir.com/YOUR_API_KEY')
});
const unsub = await api.rpc.state.subscribeStorage(
['0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9'],
(changes) => {
console.log('Storage changed:', changes.toHuman());
}
);
// Later: unsub();Use Cases
- Live balance tracking -- Watch account balance changes in real time for wallet UIs or notification systems.
- Parameter monitoring -- Get instant notifications when Bittensor subnet parameters, staking configurations, or governance values change.
- Event-driven processing -- Trigger downstream actions (alerts, database updates, API calls) when specific on-chain state changes.
Notes
- Cancel the subscription with
state_unsubscribeStoragewhen no longer needed to free server resources. - The initial notification includes the current values of all watched keys.
- This is a WebSocket-only method; not available over HTTP.
Related Methods
state_unsubscribeStorage-- Cancel this subscriptionstate_queryStorage-- Query historical storage changes over a block rangestate_queryStorageAt-- Point-in-time storage querychain_subscribeNewHeads-- Subscribe to new block headers