Storage Queries
Query on-chain storage
// Query account balance
const balance = await client.query.system.account(<address>);
// Get all events of current block
const events = await client.query.system.events();Subscribe to on-chain storage
// Subscribe to account balance changes
const unsub = await client.query.system.account(<address>, (balance) => {
console.log('New free balance', balance.data.free);
unsub(); // unsubsribe from the subscription
});
// Subscribe to events of current best block
const unsub = await client.query.system.events((records) => {
const transferEvent = client.events.balances.Transfer.find(records);
if (transferEvent) {
console.log('New transfer event: ', transferEvent);
unsub(); // unsubsribe from the subscription
}
});Multi queries
Same storage types
Different storage types
Last updated