This repo contains a series of python jupyter-notebooks to explain how bitcoin transactions are created and signed. The notebooks will start up an instance of bitcoind in regtest mode so that transactions can be validated and broadcasted on regtest. Each notebook has some questions and exercises to test your understanding.
- A high level understanding of the bitcoin. e.g. Mastering Bitcoin by Andreas Antonopoulos UTXO model, in particular Chapter 6.
- A conceptual understanding of hash functions.
- Hexadecimal notation and endianness.
- Chapter 1: 'Legacy Transactions'
- Chapter 2: 'Segwit v0'
- Chapter 3: 'Taproot'
- Chapter 4: 'Signature hashes'
- Chapter 5: 'Timelocks'
- Appendix:
This project requires Python 3.6 (or greater) to be installed on your machine already. All other dependencies will be installed automatically with pip3.
To verify your Python version, run
python3 --version
If it is properly installed, you should see something like:
Python 3.9.13
To copy the repository to your local machine, it is recommended to use git
but alternatively you can also download the files directly from GitHub, there are no further dependencies on git
.
git clone https://github.com/DariusParvin/bitcoin-tx-tutorial
cd bitcoin-tx-tutorial
To create a virtual environment and install all dependencies:
python3 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt
Finally, to launch the interactive notebook:
jupyter notebook
The notebooks in this repo use bitcoin core's TestShell
from its test framework. The TestShell
is used to create a local test instance of a bitcoin node (and blockchain) against which we can test our manually created transactions. The notebooks in this repo have been tested with bitcoin core v24.0.1.
- bitcoin-tx-color-coder: A tool for decoding raw transactions. It color-codes and interprets the bytes, similar to the examples in this tutorial.
- BitcoinIDE: Allows testing of Bitcoin stack operations and script analysis. Useful for understanding script evaluations.
- This work wouldn't have been possible without the funding from chaincode.
- A lot of the code and inspiration for this tutorial comes from the following places:
- Shlomi Zeltsinger's segwit tutorial
- Jimmy Song's Programming Bitcoin exercises.
- Bitcoin Optech Schnorr Taproot Workshop