⚠️Blast API (blastapi.io) ends Oct 31. Migrate to Dwellir and skip Alchemy's expensive compute units.
Switch Today →
Skip to main content

chain_getFinalizedHead - JSON-RPC Method

Description

Returns the hash of the latest finalized block. In Moonbase Alpha, blocks are finalized through the GRANDPA finality gadget, providing deterministic finality. This JSON-RPC method is crucial for applications that need to ensure transactions are irreversible.

Parameters

This method does not require any parameters.

Returns

FieldTypeDescription
resultstringHex-encoded hash of the latest finalized block

Request Example

{
"jsonrpc": "2.0",
"method": "chain_getFinalizedHead",
"params": [],
"id": 1
}

Response Example

{
"jsonrpc": "2.0",
"result": "0xa39d25f8cf7ad27e6a739dc15d4d013bdc48b6e2819bb74c72822a930adb5649",
"id": 1
}

Code Examples

curl https://api-moonbase-alpha.n.dwellir.com/YOUR_API_KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "chain_getFinalizedHead",
"params": [],
"id": 1
}'

Finality in Moonbase Alpha

GRANDPA Finality

  • Deterministic: Once finalized, blocks cannot be reverted
  • Fast: Typically finalizes within 12-60 seconds
  • Byzantine Fault Tolerant: Secure with up to 1/3 malicious validators

Finalization Process

  1. Block is produced by BABE
  2. Block propagates through network
  3. GRANDPA validators vote on chains
  4. Super-majority agreement finalizes block

Use Cases

  1. Exchange Deposits: Wait for finalization before crediting
  2. Smart Contract Events: Ensure events are permanent
  3. Cross-chain Bridges: Transfer assets after finalization
  4. Block Explorers: Display finalized vs unfinalized blocks
  5. Monitoring Tools: Track finalization performance

Finalization Monitoring

// Monitor finalization progress
async function monitorFinalization() {
let lastFinalized = await getFinalizedHead();

setInterval(async () => {
const currentFinalized = await getFinalizedHead();

if (currentFinalized !== lastFinalized) {
console.log('New finalized block:', currentFinalized);

// Check how many blocks were finalized
const oldBlock = await getBlock(lastFinalized);
const newBlock = await getBlock(currentFinalized);

const oldNumber = parseInt(oldBlock.block.header.number, 16);
const newNumber = parseInt(newBlock.block.header.number, 16);

console.log(`Finalized ${newNumber - oldNumber} blocks`);
lastFinalized = currentFinalized;
}
}, 6000); // Check every 6 seconds
}

Notes

  • Finalized blocks are immutable and cannot be reverted
  • Finalization typically lags 2-10 blocks behind the latest block
  • During network issues, finalization may stall temporarily
  • Always use finalized blocks for critical operations
  • Finalization provides stronger guarantees than probabilistic finality