eth_getUncleByBlockNumberAndIndex
JSON-RPC method returns information about an uncle block by block number and uncle index position. Uncle blocks are valid blocks that were not included in the main chain but are referenced by the main chain blocks for network security.
null
if no uncle exists at the specified index.
null
if no uncle exists at the specified index"latest"
— The most recent block in the chain"earliest"
— The genesis block (block 0)"pending"
— The pending state/transactions// Get uncle block by number and index
const getUncleByBlockNumberAndIndex = async (blockNumber, uncleIndex) => {
const response = await fetch('https://hyperliquid-mainnet.core.chainstack.com/YOUR_ENDPOINT/evm', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
jsonrpc: '2.0',
method: 'eth_getUncleByBlockNumberAndIndex',
params: [blockNumber, uncleIndex],
id: 1
})
});
const data = await response.json();
return data.result;
};
// Monitor latest block for uncles
const monitorLatestBlockUncles = async () => {
const uncles = [];
let index = 0;
while (true) {
const uncle = await getUncleByBlockNumberAndIndex(
'latest',
`0x${index.toString(16)}`
);
if (uncle === null) {
break;
}
uncles.push(uncle);
index++;
}
return uncles;
};
// Check uncles in a specific block
const checkBlockUncles = async (blockNumber) => {
const result = {
blockNumber,
uncles: [],
uncleCount: 0
};
let index = 0;
while (true) {
const uncle = await getUncleByBlockNumberAndIndex(
blockNumber,
`0x${index.toString(16)}`
);
if (uncle === null) {
break;
}
result.uncles.push(uncle);
index++;
}
result.uncleCount = result.uncles.length;
return result;
};
// Usage
monitorLatestBlockUncles().then(uncles => {
console.log(`Latest block has ${uncles.length} uncles`);
});
checkBlockUncles('0x100').then(result => {
console.log(`Block ${result.blockNumber} has ${result.uncleCount} uncles`);
});
curl -X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_getUncleByBlockNumberAndIndex",
"params": [
"latest",
"0x0"
],
"id": 1
}' \
https://hyperliquid-mainnet.core.chainstack.com/4f8d8f4040bdacd1577bff8058438274/evm
eth_getUncleByBlockNumberAndIndex
method is useful for applications that need to: