1

if I first get the block hash of a block at height A. Later on I get the block hash of the block at height A again, if the block hashes differ, does that mean the first block became uncle?

Example code:

const { ethers } = require('ethers');

async function checkForUncle(provider, blockNumber) {
  // Get the block hash at the first time
  const firstBlockHash = await provider.getBlockHash(blockNumber);
  console.log(`First Block Hash at Height ${blockNumber}: ${firstBlockHash}`);

  // Wait for some time, or perform other actions...

  // Get the block hash again
  const secondBlockHash = await provider.getBlockHash(blockNumber);
  console.log(`Second Block Hash at Height ${blockNumber}: ${secondBlockHash}`);

  // Compare the block hashes
  if (firstBlockHash !== secondBlockHash) {
    console.log(`The block at height ${blockNumber} became an uncle.`);
  } else {
    console.log(`The block at height ${blockNumber} is still on the main chain.`);
  }
}

const provider = new ethers.providers.JsonRpcProvider('url');
const blockNumber = 123456;

checkForUncle(provider, blockNumber);

1 Answer 1

1

Uncles were only in Ethereum's early years when it was using Proof of Work.

In Ethereum's Proof of Stake, when a block is replaced by another block, the common case would be called an orphan block. This happens when the block proposer (validator) for N+2, builds upon block N, instead of N+1. If other validators continue building on N+2, then N+1 gets orphaned.

A rare case would be a "double proposal" (or multi proposal). These are rare because the block proposer (validator) will get slashed. The validator would lose part of their stake, and would have to restake if they want to be a validator again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.