Skip to content

Instantly share code, notes, and snippets.

@markodayan
Created August 22, 2022 04:06
Show Gist options
  • Save markodayan/358c0cebcb0eabf672a414ce99eb5fcd to your computer and use it in GitHub Desktop.
Save markodayan/358c0cebcb0eabf672a414ce99eb5fcd to your computer and use it in GitHub Desktop.
Calculate Ethereum block header
import createKeccakHash from 'keccak';
function calculateBlockHeader(block: IRawBlock): string {
const tuple = prepareBlockTuple(block);
const encoded = Buffer.from(encode(tuple));
const calculated = createKeccakHash('keccak256').update(encoded).digest('hex');
return '0x' + calculated;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment