This program is able to generate a P2SH address with a CSV timelock, as well as spending all UTXOs associated with the P2SH address. Both these functions can be accomplished by following the instructions below.
When sending funds to the P2SH address, the UTXOs will be locked until they have been confirmed for the specified amount of blocks. Additionally, the program assumes that the bitcoin core client is installed locally!
!!! Be aware, this program is purely intended for educational purposes, and should only be used on the Bitcoin testnet !!!
$ python3 setup.py
- creates new venv
- installs dependencies
- confirms succesfull setup
$ mkdir venv
$ python3 -m venv venv
$ source ./venv/bin/activate
$ pip3 install bitcoin-utils requests
$ source ./venv/bin/activate
$ python3 main.py config_data
- inserts a
priv_key
queried from bitcoin-cli - inserts a
p2pkh address
queried from bitcoin-cli - inserts a
block_lock
randomly chosen between 100-400 blocks
-
eg.
pub_key
: "023e17859419f46552bc0a5856ff8f7f523b7e877ec8bde3fd53334a5b13a14fae" -
eg.
priv_key
: "cUD74njAVhJAsCV1Npg9zY2fCPFTFe6pfJ6nPAEweBMBjP9ZenZs"If both keys are provided, the program defaults to using priv_key. The priv_key must be included in order to spend from the P2SH address.
- eg.
block_lock
: 200
- eg.
p2pkh_address
: "mttbFoMwL3g4Y3UTfMin19hx2x9i94nE7D"
$ source ./venv/bin/activate
$ python3 main.py p2sh_create
- creates a new P2SH address with csv script
p2sh_address
&script_hash
is displayed in terminal and saved indata.json
$ source ./venv/bin/activate
$ python3 main.py p2sh_fill
$ bitcoin-cli sendtoaddress <p2sh_address> <amount>
$ bitcoin-cli generate <timelock>
Grab a coffe and wait :)
$ source ./venv/bin/activate
$ python3 main.py p2sh_spend
-
creates a transaction that spends all UTXOs of P2SH address,
-
broadcasts the transaction via bitcoin-cli
-
tx_id
&tx_signed
is displayed in terminal and saved indata.json
Note: The program assumes that the UTXOs send to the P2SH address were created/signed/broadcasted from the locally running bitcoin client, this assumption is critical for the program to automatically gather the input UTXOs for creating the spending from P2SH address transaction. If this assumption does not hold, then the program is unable to collect the transaction input UTXOs for the spending transaction. The program is able to handle multiple UTXOs send to the P2SH address.
Additionally, the program estimates the required fee for sending the transaction, if the required fee is larger than the balance of the P2SH's UTXOs, then the program will prompt the user to either exit and send additional balance to the P2SH address, or to specify a custom fee.