useBlockInfo
Subscribes to best and finalized block updates in real time. Returns block number and hash for both best and finalized blocks with automatic updates.
Props
Name
Type
Description
options
NetworkOptions?
Optional network selection options (e.g., { networkId: 'polkadot' }
).
Return Type
Name
Type
Description
best
BlockInfo | undefined
Latest best block information ({ number: number, hash: string }
).
finalized
BlockInfo | undefined
Latest finalized block information ({ number: number, hash: string }
).
Basic Usage
Display real-time block numbers:
import { useBlockInfo } from 'typink';
function BlockTracker() {
const { best, finalized } = useBlockInfo();
return (
<div>
<p>Best Block: #{best?.number}</p>
<p>Finalized Block: #{finalized?.number}</p>
<p>Best Hash: {best?.hash}</p>
</div>
);
}
Multi-network block tracking:
function MultiNetworkBlocks() {
const polkadotBlocks = useBlockInfo({ networkId: 'polkadot' });
const kusamaBlocks = useBlockInfo({ networkId: 'kusama' });
return (
<div>
<div>
<h3>Polkadot</h3>
<p>Best: #{polkadotBlocks.best?.number}</p>
<p>Finalized: #{polkadotBlocks.finalized?.number}</p>
</div>
<div>
<h3>Kusama</h3>
<p>Best: #{kusamaBlocks.best?.number}</p>
<p>Finalized: #{kusamaBlocks.finalized?.number}</p>
</div>
</div>
);
}
Last updated
Was this helpful?