Scripts to create transactions with different output types and spend them, leveraging the bitcoin core test_framework
The scripts in this repository are created to help people learning Bitcoin, and developers starting in Bitcoin, to understand how transactions, with different types of outputs, are constructed and broadcast to the Bitcoin network.
The repository lives separately from the bitcoin/bitcoin
core repository, however a couple of symlinks can be created to be able to leverage your local copy of the functional test_framework. If you already have a directory where you build Bitcoin Core, the symlinks have to be adjusted to point to your local Bitcoin Core repository, in my case they are the following:
- in this project home directory:
ln -s ~/bitcoin-core/bitcoin/test/config.ini config.ini
- in this project
functional
directory:ln -s ~/bitcoin-core/bitcoin/test/functional/test_framework test_framework
By doing this, the scripts in the functional folder use the first symlink to share the configuration created by ./configure
by bitcoin core. In this way the scripts can look for the test_framework
objects directly from your Bitcoin Core directory, by using the second symlink.
Scripts in the funcional repository can be run directly typing the name of the script ./create_P2PK.py
. Note the file needs execution permissions (chmod +x <file>)
.
The options provided by the test_framework can be used, for example ./create_P2PK.py --loglevel=DEBUG --tracerpc
.
If you want to know the available options use ./create_P2PK.py -h
Standard transaction types accepted by the Bitcoin network and the miners.
vout | scriptPubKey | scriptSig | redeem script |
witness-stack |
---|---|---|---|---|
P2PK |
<pubKey> OP_CHECKSIG |
<signature> |
||
P2PKH |
OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG |
<signature> <publicKey> |
||
P2SH |
OP_HASH160 scriptHash OP_EQUAL |
data_pushes <redemScript> |
arbitrary |
|
P2WPKH |
0<pubKeyHash> |
<signature> <publicKey> |
||
P2WSH |
0<witnessScriptHash> |
<witnessScript> |
||
P2SH-P2WPKH |
OP_HASH160 <redemScriptHash> OP_EQUAL |
<redemScript> |
0<pubKeyHash> |
<signature> <publicKey> |
P2SH-P2WSH |
OP_HASH160 <redemScriptHash> |
<redemScript> |
0<scriptHash> |
<witnessScript> |
P2TR (key path) |
1<publicKey> |
<signature> |
||
P2TR (script path ) |
1<publicKey> |
[Stack element(s) satisfying tapscript] <script> [control_block] |
This table was produced by Gloria Zhao1
- Create P2PK (Not recommended)
- Create P2PKH
- Create MultiSig (legacy Multisig)
- Create P2WPKH case study, P2WPKH Python script
- Create P2TR (Key Path) case study, P2TR Key Path Python script
- Create P2TR (Script Path) case study, P2TR Script Path Python script