I am trying to verify the blocks without having the access to an RPC, I using blockheader and trying to generate a blockhash using the data in blockheader, cannot figureout the exact flow for it.
Written multiple scripts like below but not able to get exact match till now.
const {
hash,
parentHash,
sha3Uncles,
miner,
stateRoot,
transactionsRoot,
logsBloom,
difficulty,
number,
gasLimit,
gasUsed,
timestamp,
extraData,
mixHash,
nonce,
} = await web3.eth.getBlock(blockNumber);
preEncode = [
parentHash,
sha3Uncles,
miner,
stateRoot,
transactionsRoot,
logsBloom,
web3.utils.toHex(difficulty),
web3.utils.toHex(number),
web3.utils.toHex(gasLimit),
web3.utils.toHex(gasUsed),
web3.utils.toHex(timestamp),
extraData,
mixHash,
nonce,
];
// getting RLP hash
let encoded = util.rlp.encode(preEncode);
// Hashing the RLP output
const hashedOutput = web3.utils.sha3(
web3.utils.sha3(util.bufferToHex(encoded))
);