Skip to content
Taproot & Schnorr Python Library & Documentation.
Python Jupyter Notebook
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
images Huffman constructor chapter completed. Nov 8, 2019
solutions Rename Node/node to Tapbranch/tapbranch Nov 11, 2019
test_framework Add TapLeaf constructor from descriptor Nov 27, 2019
.gitignore Add vim files to gitignore Sep 2, 2019
0.1-test-notebook.ipynb lowercase all images and move to image directory Oct 8, 2019
0.2-elliptic-curve-math.ipynb Fixes tiny mistake in `0.2-elliptic-curve-math` Nov 5, 2019
0.3-tagged-hashes.ipynb add 0.3 chapter for tagged hashes Oct 17, 2019
1.1-schnorr-signatures.ipynb typo: FIELD_SIZE, not ORDER Dec 2, 2019
1.2-musig.ipynb Remove direct hashlib.sha256() calls Oct 17, 2019
2.0-taproot-introduction.ipynb Added CTxInWitness(witness_stack) initialization to chapter 2.0. Oct 28, 2019
2.1-segwit-version-1.ipynb Add case study to chapter 2.1 Oct 29, 2019
2.2-taptweak.ipynb Added CTxInWitness(witness_stack) initialization to chapter 2.2 Oct 28, 2019
2.3-tapscript.ipynb Chain tapscript constructor to initializer Nov 1, 2019
2.4-taptree.ipynb Spelling correction: leafs to leaves Nov 8, 2019
2.5-huffman.ipynb Use Tapbranch and Taptree constructors in huffman chapter Nov 11, 2019
3.1-degrading-multisig-case-study.ipynb Chain tapscript constructor to initializer Nov 1, 2019 add: Google Colab section Nov 27, 2019
config.ini Use config.ini for configuration Sep 4, 2019
requirements.txt Update and add requirements.txt Aug 28, 2019 Make generate_and_send_coins send rewards to bech32 address. Nov 8, 2019


This repo contains the Jupyter notebooks for Optech's Schnorr/Taproot workshops.


For the purposes of demonstrating the features of schnorr and taproot to the Bitcoin developer community, we have developed an extended Python library on top of Pieter Wuille's Taproot Bitcoin Core branch, which provides Python classes and methods to build more sophisticated Taproot transactions and various schnorr signature schemes for preliminary evaluation.

Our Taproot/Schnorr library is an extension of the Bitcoin python test framework, located in the dedicated Optech Bitcoin Taproot Branch.

Note: This Library is intended for demonstrative and educational purposes only.


Do not run test instances of bitcoind on the same machine that you store your Bitcoin private keys. These notebooks shouldn't interfere with your standard bitcoin data directory, but why risk it?


It will be useful to have some background on schnorr and taproot before running through the exercises in this repository.



Output Descriptors

Running the notebooks

The notebooks can either be run in the cloud or in a local Jupyter environment.

Google Colab cloud

Google Colab is a Jupyter notebook environment that requires no setup, is free to use and runs entirely in the Google cloud. Running the Optech Schnorr/Taproot workshop in Google Colab requires you to login with your Google account. The Colab environment disconnects your runtime after 30 minutes of inactivity and has a maximum session length of 12 hours. Don't forget to save your progress. You can have multiple runtimes and notebooks open at the same time.

The following notebooks are located in the Colab branch of this repository and are modified to run on Google Colab.

Local setup

The Optech Schnorr/Taproot workshop can be setup and run locally. This section lists the necessary steps and requirements.

Clone this (bitcoinops/taproot-workshop) repository

$ git clone

Build a taproot-supporting bitcoind

These workbooks require a bitcoind built from the Optech Taproot V0.1.4 branch which supports schnorr and taproot.


Clone the bitcoinops/bitcoin repository in a separate directory from this taproot-workshop repository:

$ git clone

Note the path where you cloned the bitcoinops/bitcoin repository and add it to the config.ini file in your taproot-workshop repository. For example, set:


Checkout the Optech taproot branch in the bitcoinops/bitcoin repository, which is tagged as Taproot_V0.1.4:

$ git checkout Taproot_V0.1.4

Build the Optech Taproot branch of bitcoind locally. See the build documentation ( in the Bitcoin Core repository docs directory for additional documentation on building bitcoind on Unix, macOS, or Windows.

No need to run bitcoind or download the mainchain or testnet blockchain. We will run in regtest mode and spawn node instances via scripts.

Python 3

Verify you have python3 installed:

$ python3 --version

If not, you should install Python 3.


$ sudo apt-get install python3

macOS (using homebrew):

$ brew install python3


Python Dependencies

This workshop uses some Python dependencies, particularly jupyter-notebook. To keep dependencies local to the project, you should create and activate a virtual environment. You can skip this step if you're happy to install the dependencies globally.

Make sure you are in your taproot-workshop repository folder.

$ python3 -m venv .venv && source .venv/bin/activate

(if you're using the csh or fish shells, replace .venv/bin/activate with .venv/bin/activate.csh or .venv/bin/

Install dependencies:

$ pip3 install -r requirements.txt

Ensure jupyter notebook is installed:

$ jupyter notebook --version

Jupyter notebook is a handy tool which allow us to run python code directly in an interactive document like this one. The workshop materials are built directly with jupyter .ipynb files, which you can open once you have jupyter installed.

Start jupyter notebook to see exercises:

$ jupyter notebook

Jupyter will start a notebook server in your terminal, and provide a link for your browser from which you can interact with notebook files. If your browser doesn't automatically open the notebook file explorer, click on the link provided by jupyter notebook server in the terminal.

  • Click on the 0.1-test-notebook.ipynb notebook.
  • Verify that 0.1-test-notebook.ipynb passes all checks.

After you have run the 0.1 example exercises, please also run through the 0.2-elliptic-curve-math.ipynb and 0.3-tagged-hashes.ipynb notebooks and exercises before the workshop.

Notebooks 1.x, 2.x, etc will be covered during the workshop. There is no need to run through those beforehand.

Stop the current running jupyter session using Control-C in the terminal.

After you have finished your jupyter session, you can deactivate the Python virtual environment with:

$ deactivate
You can’t perform that action at this time.