Sample code in different languages to compute merkle root as per bitcoin implementation.
The bitcoin merkle tree differs from a standard merkle tree implementation in two ways
- Bitcoin uses little endian notation
- Double hashing against length extension attacks
language | status |
---|---|
Python | Complete |
JS | Complete |
Rust | Pending |
Golang | Pending |
- Ensure you have python3 installed
- Open
merkle.py
and changeSELECTED_BLOCK_HASH
to the block hash you want to test - Run
python3 merkle.py
and compare merkle root with block explorer
- Run
npm i
- Open
merkle.js
and changeSELECTED_BLOCK_HASH
to the block hash you want to test - Run
node merkle.js
and compare merkle root with block explorer