from bitcoinutils.transactions import Transaction, TxInput, TxOutput from bitcoinutils.script import Script from bitcoinutils.setup import setup from bitcoinutils.keys import P2pkhAddress, PrivateKey from bitcoinutils.constants import TYPE_RELATIVE_TIMELOCK from bitcoinutils.utils import to_satoshis # Setup the Bitcoin network setup('mainnet') # Define private keys and addresses priv = PrivateKey('cRKQhZMAaFSpKNdsLKUszEyGyPo9eHhWioXE8utG6z77Em27wTLi') pub = priv.get_public_key() addr = pub.get_taproot_address() # Create a new transaction tx = Transaction([], []) # Define the script using Taproot's flexible conditions taproot_script = Script([pub.to_hex(), 'OP_CHECKSIG']) # Define the input and output input = TxInput('transaction_id', 0) output = TxOutput(to_satoshis(0.01), addr.to_script_pub_key()) # Add the input and output to the transaction tx.add_input(input) tx.add_output(output) # Sign the transaction using Schnorr signature sig = priv.sign_input(tx, 0, taproot_script) # Verify and broadcast the transaction tx = Transaction([input], [output]) tx.inputs[0].script_sig = Script([sig, pub.to_hex()]) print(tx.serialize())