### Full Example: Address Generation and Usage Source: https://github.com/karask/python-bitcoin-utils/blob/master/docs/usage/addresses.md Demonstrates comprehensive address generation, including SegWit and P2SH/P2WSH variants, and setup for testnet. Imports necessary classes from `bitcoinutils` and uses `setup()`. ```python # Copyright (C) 2018-2025 The python-bitcoin-utils developers # # This file is part of python-bitcoin-utils # # It is subject to the license terms in the LICENSE file found in the top-level # directory of this distribution. # # No part of python-bitcoin-utils, including this file, may be copied, # modified, propagated, or distributed except according to the terms contained # in the LICENSE file. from bitcoinutils.setup import setup from bitcoinutils.script import Script from bitcoinutils.keys import P2wpkhAddress, P2wshAddress, P2shAddress, PrivateKey def main(): # always remember to setup the network setup("testnet") # could also instantiate from existing WIF key priv = PrivateKey.from_wif("cVdte9ei2xsVjmZSPtyucG43YZgNkmKTqhwiUA8M4Fc3LdPJxPmZ") # compressed is the default print("\nPrivate key WIF:", priv.to_wif(compressed=True)) # get the public key pub = priv.get_public_key() # compressed is the default print("Public key:", pub.to_hex(compressed=True)) # get address from public key address = pub.get_segwit_address() # print the address and hash - default is compressed address print("Native Address:", address.to_string()) segwit_hash = address.to_witness_program() print("Segwit Hash (witness program):", segwit_hash) print("Segwit Version:", address.get_type()) # test to_string addr2 = P2wpkhAddress.from_witness_program(segwit_hash) print("Created P2wpkhAddress from Segwit Hash and calculate address:") print("Native Address:", addr2.to_string()) # # display P2SH-P2WPKH # # create segwit address addr3 = ( PrivateKey.from_wif("cTmyBsxMQ3vyh4J3jCKYn2Au7AhTKvqeYuxxkinsg6Rz3BBPrYKK") .get_public_key() .get_segwit_address() ) # wrap in P2SH address addr4 = P2shAddress.from_script(addr3.to_script_pub_key()) print("P2SH(P2WPKH):", addr4.to_string()) # # display P2WSH # p2wpkh_key = PrivateKey.from_wif( "cNn8itYxAng4xR4eMtrPsrPpDpTdVNuw7Jb6kfhFYZ8DLSZBCg37" ) script = Script( ["OP_1", p2wpkh_key.get_public_key().to_hex(), "OP_1", "OP_CHECKMULTISIG"] ) p2wsh_addr = P2wshAddress.from_script(script) print("P2WSH of P2PK:", p2wsh_addr.to_string()) # # display P2SH-P2WSH # p2sh_p2wsh_addr = P2shAddress.from_script(p2wsh_addr.to_script_pub_key()) print("P2SH(P2WSH of P2PK):", p2sh_p2wsh_addr.to_string()) if __name__ == "__main__": main() ``` -------------------------------- ### Full HD Wallet Example Source: https://github.com/karask/python-bitcoin-utils/blob/master/docs/usage/hdwallet.md A comprehensive example demonstrating HD wallet functionality. It covers creating wallets from mnemonics and extended private keys, deriving keys from various BIP paths (legacy, SegWit, Taproot), and switching paths on the same wallet instance. Requires testnet setup. ```python # Copyright (C) 2018-2025 The python-bitcoin-utils developers # # This file is part of python-bitcoin-utils # # It is subject to the license terms in the LICENSE file found in the top-level # directory of this distribution. # # No part of python-bitcoin-utils, including this file, may be copied, # modified, propagated, or distributed except according to the terms contained # in the LICENSE file. """Detailed HD wallet examples. This example demonstrates the minimal HD functionality provided by bitcoinutils: * create a wallet from a BIP-39 mnemonic * derive private keys from different BIP-style paths * derive legacy, segwit v0, and taproot addresses from the same key * switch paths on the same HDWallet instance * create a wallet from an extended private key The mnemonic and extended private keys below are for testnet examples only. Do not use them with real funds. """ from bitcoinutils.setup import setup from bitcoinutils.hdwallet import HDWallet def print_key_details(title, hdw): """Print the currently selected key and common address types.""" privkey = hdw.get_private_key() pubkey = privkey.get_public_key() print(f"\n{title}") print("-" * len(title)) print("WIF:", privkey.to_wif()) print("Public key:", pubkey.to_hex()) print("Legacy P2PKH:", pubkey.get_address().to_string()) print("Native Segwit P2WPKH:", pubkey.get_segwit_address().to_string()) print("Taproot P2TR:", pubkey.get_taproot_address().to_string()) def derive_and_print(hdw, path): """Derive an absolute path and print the resulting key/address details.""" hdw.from_path(path) print_key_details(f"Path {path}", hdw) def main(): setup("testnet") mnemonic = ( "addict weather world sense idle purity rich wagon " "ankle fall cheese spatial" ) print("Mnemonic wallet") print("===============") print("Mnemonic:", mnemonic) hdw_from_mnemonic = HDWallet(mnemonic=mnemonic) # BIP-44: legacy P2PKH-style account path. derive_and_print(hdw_from_mnemonic, "m/44'/1'/0'/0/0") derive_and_print(hdw_from_mnemonic, "m/44'/1'/0'/0/1") # BIP-84: native segwit account path. The private/public key can still be # rendered as multiple address types; the path communicates wallet intent. derive_and_print(hdw_from_mnemonic, "m/84'/1'/0'/0/0") # BIP-86: taproot account path. derive_and_print(hdw_from_mnemonic, "m/86'/1'/0'/0/0") print("\nSwitching paths") print("===============") hdw_from_mnemonic.from_path("m/44'/1'/0'/0/3") addr_a = hdw_from_mnemonic.get_private_key().get_public_key().get_address() print("m/44'/1'/0'/0/3 legacy address:", addr_a.to_string()) hdw_from_mnemonic.from_path("m/44'/1'/0'/0/4") addr_b = hdw_from_mnemonic.get_private_key().get_public_key().get_address() print("m/44'/1'/0'/0/4 legacy address:", addr_b.to_string()) xprivkey = ( "tprv8ZgxMBicQKsPdQR9RuHpGGxSnNq8Jr3X4WnT6Nf2eq7FajuXyBep5KWYpYEixxx5XdTm1N" "tpe84f3cVcF7mZZ7mPkntaFXLGJD2tS7YJkWU" ) print("\nExtended private key wallet") print("===========================") print("Extended private key:", xprivkey) hdw_from_xpriv = HDWallet.from_xprivate_key(xprivkey, "m/86'/1'/0'/0/1") print_key_details("Path m/86'/1'/0'/0/1", hdw_from_xpriv) hdw_from_xpriv.from_path("m/86'/1'/0'/0/5") print_key_details("Path m/86'/1'/0'/0/5", hdw_from_xpriv) if __name__ == "__main__": main() ``` -------------------------------- ### Run Examples with PYTHONPATH Source: https://github.com/karask/python-bitcoin-utils/blob/master/docs/usage/quickstart.md When running examples directly from a local checkout of the repository, set the PYTHONPATH environment variable to ensure Python imports the local code instead of an installed package. ```bash PYTHONPATH=. venv/bin/python examples/p2pkh_transaction.py ``` -------------------------------- ### Full Key and Message Example Source: https://github.com/karask/python-bitcoin-utils/blob/master/docs/usage/keys.md A comprehensive example demonstrating private key creation, public key retrieval, address generation, message signing, and verification on the mainnet. ```python # Copyright (C) 2018-2025 The python-bitcoin-utils developers # # This file is part of python-bitcoin-utils # # It is subject to the license terms in the LICENSE file found in the top-level # directory of this distribution. # # No part of python-bitcoin-utils, including this file, may be copied, # modified, propagated, or distributed except according to the terms contained # in the LICENSE file. from bitcoinutils.setup import setup from bitcoinutils.keys import PrivateKey, PublicKey def main(): # always remember to setup the network setup("mainnet") # create a private key (deterministically) priv = PrivateKey(secret_exponent=1) # compressed is the default print("\nPrivate key WIF:", priv.to_wif(compressed=True)) # could also instantiate from existing WIF key # priv = PrivateKey.from_wif('KwDiBf89qGgbjEhKnhxjUh7LrciVRzI3qYjgd9m7Rfu73SvHnOwn') # get the public key pub = priv.get_public_key() # compressed is the default print("Public key:", pub.to_hex(compressed=True)) # get address from public key address = pub.get_address() # print the address and hash160 - default is compressed address print("Address:", address.to_string()) print("Hash160:", address.to_hash160()) print("\n--------------------------------------\n") # sign a message with the private key and verify it message = "The test!" signature = priv.sign_message(message) assert signature is not None print("The message to sign:", message) print("The signature is:", signature) if PublicKey.verify_message(address.to_string(), signature, message): print("The signature is valid!") else: print("The signature is NOT valid!") if __name__ == "__main__": main() ``` -------------------------------- ### Comprehensive Bitcoin Core RPC Interaction Example Source: https://github.com/karask/python-bitcoin-utils/blob/master/docs/usage/proxy.md Demonstrates setup for a specific network (regtest) and interaction with various Bitcoin Core RPC methods including block information, blockchain status, network details, mempool stats, and wallet operations. Handles potential errors for wallet commands. ```python # Copyright (C) 2018-2025 The python-bitcoin-utils developers # # This file is part of python-bitcoin-utils # # It is subject to the license terms in the LICENSE file found in the top-level # directory of this distribution. # # No part of python-bitcoin-utils, including this file, may be copied, # modified, propagated, or distributed except according to the terms contained # in the LICENSE file. from bitcoinutils.setup import setup from bitcoinutils.proxy import NodeProxy def main(): # always remember to setup the network setup("regtest") # get a node proxy using default host and port proxy = NodeProxy("rpcuser", "rpcpw") # call the node's getblockcount JSON-RPC method count = proxy.getblockcount() # call the node's getblockhash JSON-RPC method block_hash = proxy.getblockhash(count) # call the node's getblock JSON-RPC method and print result block = proxy.getblock(block_hash) print("--- Block Information ---") print(f"Height: {block['height']}") print(f"Hash: {block['hash']}") print(f"Transactions: {len(block['tx'])}") print(f"Difficulty: {block['difficulty']}") print("\n--- Blockchain Information ---") binfo = proxy.getblockchaininfo() print(f"Chain: {binfo['chain']}") print(f"Blocks: {binfo['blocks']}") print(f"Size on disk: {binfo['size_on_disk']} bytes") print("\n--- Network Information ---") ninfo = proxy.getnetworkinfo() print(f"Version: {ninfo['version']}") print(f"Subversion: {ninfo['subversion']}") print(f"Connections: {ninfo['connections']}") print("\n--- Mempool Information ---") minfo = proxy.getmempoolinfo() print(f"Size: {minfo['size']} transactions") print(f"Bytes: {minfo['bytes']} bytes") print("\n--- Wallet Information ---") try: # These commands require a loaded wallet balance = proxy.getbalance() print(f"Balance: {balance} BTC") new_addr = proxy.getnewaddress() print(f"New address: {new_addr}") except Exception as e: print(f"Wallet commands failed (no wallet loaded?): {e}") if __name__ == "__main__": main() ``` -------------------------------- ### Setup Bitcoin Network Source: https://github.com/karask/python-bitcoin-utils/blob/master/docs/usage/quickstart.md Select the Bitcoin network (e.g., 'testnet', 'mainnet', 'regtest') before performing any operations. This is a mandatory first step. ```python from bitcoinutils.setup import setup setup("testnet") ``` -------------------------------- ### Install Package in Development Mode Source: https://github.com/karask/python-bitcoin-utils/blob/master/CONTRIBUTING.md Install the package in editable mode to facilitate local development and testing. ```sh pip install -e . ``` -------------------------------- ### Address Type Examples Source: https://context7.com/karask/python-bitcoin-utils/llms.txt Demonstrates creating and converting various Bitcoin address types including P2PKH, P2SH, P2WPKH, P2WSH, and P2TR. ```python from bitcoinutils.script import Script from bitcoinutils.addresses import P2pkhAddress, P2shAddress, P2wpkhAddress, P2wshAddress, P2trAddress # P2PKH — legacy addr = P2pkhAddress("n4bkvTyU1dVdzsrhWBqBw8fEMbHjJvtmJR") print(addr.to_hash160()) # 20-byte hash as hex spk = addr.to_script_pub_key() # OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG # P2SH — from a redeem script redeem = Script(["OP_2", "", "", "", "OP_3", "OP_CHECKMULTISIG"]) p2sh = P2shAddress(script=redeem) print(p2sh.to_string()) # 2... print(p2sh.to_script_pub_key().to_hex()) # OP_HASH160 OP_EQUAL # P2WPKH — native segwit v0 from bech32 string wpkh = P2wpkhAddress("tb1qlffsz7cgzmyzhklleu97afru7vwjytux4z4zsl") print(wpkh.to_witness_program()) # hash160 as hex print(wpkh.to_script_pub_key().to_hex()) # OP_0 <20-byte hash> # P2WSH — from a witness script witness_script = Script(["OP_1", "", "OP_1", "OP_CHECKMULTISIG"]) p2wsh = P2wshAddress(script=witness_script) print(p2wsh.to_string()) # P2TR — taproot from address string p2tr = P2trAddress(address="tb1p...") print(p2tr.to_script_pub_key().to_hex()) # OP_1 <32-byte x-only key> ``` -------------------------------- ### Create and Sign a Bitcoin Transaction Source: https://github.com/karask/python-bitcoin-utils/blob/master/docs/usage/transactions.md This example demonstrates how to create a raw transaction, add inputs and outputs, sign the transaction with a private key, and serialize the signed transaction. Ensure the network is set up before proceeding. ```python from bitcoinutils.setup import setup from bitcoinutils.utils import to_satoshis from bitcoinutils.transactions import Transaction, TxInput, TxOutput from bitcoinutils.keys import P2pkhAddress, PrivateKey from bitcoinutils.script import Script def main(): # always remember to setup the network setup("testnet") # create transaction input from tx id of UTXO (contained 0.4 tBTC) txin = TxInput( "fb48f4e23bf6ddf606714141ac78c3e921c8c0bebeb7c8abb2c799e9ce6c", 0 ) # create transaction output using P2PKH scriptPubKey (locking script) addr = P2pkhAddress("n4bkvTyU1dVdzsrhWBqBw8fEMbHjJvtmJR") txout = TxOutput( to_satoshis(0.1), Script( ["OP_DUP", "OP_HASH160", addr.to_hash160(), "OP_EQUALVERIFY", "OP_CHECKSIG"] ), ) # create another output to get the change - remaining 0.01 is tx fees # note that this time we used to_script_pub_key() to create the P2PKH # script change_addr = P2pkhAddress("mmYNBho9BWQB2dSniP1NJvnPoj5EVWw89w") change_txout = TxOutput(to_satoshis(0.29), change_addr.to_script_pub_key()) # change_txout = TxOutput(to_satoshis(0.29), Script(['OP_DUP', 'OP_HASH160', # change_addr.to_hash160(), # 'OP_EQUALVERIFY', 'OP_CHECKSIG'])) # create transaction from inputs/outputs -- default locktime is used tx = Transaction([txin], [txout, change_txout]) # print raw transaction print("\nRaw unsigned transaction:\n" + tx.serialize()) # use the private key corresponding to the address that contains the # UTXO we are trying to spend to sign the input sk = PrivateKey("cRvyLwCPLU88jsyj94L7iJjQX5C2f8koG4G2gevN4BeSGcEvfKe9") # note that we pass the scriptPubkey as one of the inputs of sign_input # because it is used to replace the scriptSig of the UTXO we are trying to # spend when creating the transaction digest from_addr = P2pkhAddress("myPAE9HwPeKHh8FjKwBNBaHnemApo3dw6e") sig = sk.sign_input( tx, 0, Script( [ "OP_DUP", "OP_HASH160", from_addr.to_hash160(), "OP_EQUALVERIFY", "OP_CHECKSIG", ] ), ) # print(sig) # get public key as hex pk = sk.get_public_key().to_hex() # set the scriptSig (unlocking script) txin.script_sig = Script([sig, pk]) signed_tx = tx.serialize() # print raw signed transaction ready to be broadcasted print("\nRaw signed transaction:\n" + signed_tx) # print the size of the final transaction print("\nSigned transaction size (in bytes):\n" + str(tx.get_size())) if __name__ == "__main__": main() ``` -------------------------------- ### Create and Sign a Transaction Source: https://github.com/karask/python-bitcoin-utils/blob/master/docs/usage/script.md A comprehensive example demonstrating the creation of a raw transaction, including inputs and outputs with custom locking scripts, signing an input with a private key, and serializing the signed transaction. This example requires a regtest environment with specific node configurations. ```python # Copyright (C) 2018-2025 The python-bitcoin-utils developers # # This file is part of python-bitcoin-utils # # It is subject to the license terms in the LICENSE file found in the top-level # directory of this distribution. # # No part of python-bitcoin-utils, including this file, may be copied, # modified, propagated, or distributed except according to the terms contained # in the LICENSE file. from bitcoinutils.setup import setup from bitcoinutils.utils import to_satoshis from bitcoinutils.transactions import Transaction, TxInput, TxOutput from bitcoinutils.keys import P2pkhAddress, PrivateKey from bitcoinutils.script import Script # # Note that a non-standard transaction can only be included in a block if a # miner agrees with it. For this to work one needs to use a node setup up # for regtest so that you can mine your own blocks; unless you mine your own # testnet/mainnet blocks. # Node's config file requires: # regtest=1 # acceptnonstdtxn=1 # def main(): # always remember to setup the network setup("regtest") # create transaction input from tx id of UTXO (contained 0.4 tBTC) txin = TxInput( "e2d08a63a540000222d6a92440436375d8b1bc89a2638dc5366833804287c83f", 1 ) # locking script expects 2 numbers that when added equal 5 (silly example) txout = TxOutput(to_satoshis(0.9), Script(["OP_ADD", "OP_5", "OP_EQUAL"])) # create another output to get the change - remaining 0.01 is tx fees # note that this time we used to_script_pub_key() to create the P2PKH # script change_addr = P2pkhAddress("mrCDrCybB6J1vRfbwM5hemdJz73FwDBC8r") change_txout = TxOutput(to_satoshis(2), change_addr.to_script_pub_key()) # create transaction from inputs/outputs -- default locktime is used tx = Transaction([txin], [txout, change_txout]) # print raw transaction print("\nRaw unsigned transaction:\n" + tx.serialize()) # use the private key corresponding to the address that contains the # UTXO we are trying to spend to sign the input sk = PrivateKey("cMahea7zqjxrtgAbB7LSGbcQUr1uX1ojuat9jZodMN87JcbXMTcA") # note that we pass the scriptPubkey as one of the inputs of sign_input # because it is used to replace the scriptSig of the UTXO we are trying to # spend when creating the transaction digest from_addr = P2pkhAddress("mrCDrCybB6J1vRfbwM5hemdJz73FwDBC8r") sig = sk.sign_input( tx, 0, Script( [ "OP_DUP", "OP_HASH160", from_addr.to_hash160(), "OP_EQUALVERIFY", "OP_CHECKSIG", ] ), ) # print(sig) # get public key as hex pk = sk.get_public_key() pk = pk.to_hex() # print (pk) # set the scriptSig (unlocking script) txin.script_sig = Script([sig, pk]) signed_tx = tx.serialize() # print raw signed transaction ready to be broadcasted print("\nRaw signed transaction:\n" + signed_tx) if __name__ == "__main__": main() ``` -------------------------------- ### SegWit v0 Block Example 1 Source: https://github.com/karask/python-bitcoin-utils/blob/master/tests/segwit_v0_block.txt This is an example of a SegWit v0 block structure. It includes transaction data and witness information. ```hex 012102ea02d4ff57ea87cc030d03c6bfdee982ff6feee8793623dc6695a93e0e5e4c83fdffffff02880d0100000000001976a914ceacdda47ed5af2ef22eac3eb77985c40c7a944e88ac70af0800000000001976a9144f57a59770cbcfcb35820d34bd7dde3657fca04388ac445c0b0002000000000101747dd2801f6658751fe2df89afae069b5be76b04c95f3cdfac854c4a3c210fc80100000017160014d4dd34fc219b04bc336342dccc51947a8afbadd6fdffffff02c62208000000000017a914b4e8438ada682494abc743e9fe2b4c53104d894f87021899010000000017a91471745f2f64ab5aa7d34e07c898ee886568d97a4f8702473044022050616013adb5eb05e60d7c4a8ab95f21856d29e35ea31f209186ae2a0df548a502204c944568bf14cfc6f79d597e7c627ece930c985cbb368aee987cc3020349ceed012102aad2304e5f00334f4d1e973dd4b54dfd78b5f844e35df9599759c1102fb6ddf4445c0b0002000000000102e55bee4ed687c6e997bb15d3e72f1011d62cc394aed1269ab75e37ff7e0dbf3d0000000017160014e88a436a65c498a0909e0716687d36b2bcdbcac5feffffff53eff20c96cf21ddb13182ace5324b89d52ae61025c59c265e5130663fc65ed800000000171600149919741784f35a9a6585e98670bf12b72b92d3c2feffffff01e6cf06000000000016001410caa98e9eb2e8e80d5758d6245fdc4459324c8f024730440220025b5e14071d03f87a8500dc24bcfce591c695d5b57fd3e19bcbe0308aa65e860220790118c390dccf232d9acb72cdf63866454ba3e266d31d3bd22ebe3b24838a010121036fca1d3fa65880439fccb7d064e51a619a2c2274a7465b9041da9da5fe338ab70247304402201e092e5119df0d82950e4f2bf0b284107b747826cd7d75634c269b396136b7ae022073556a2cdec32a747aa7ea7bc22d5d4b1fb7d4ccfcab0a5054baec29efadb6180121023cc877ae030c6a09624b48fddbdca23519096d9a69fd3d9bd9f5c9b7d8738d210000000002000000000101cd2fefa71e5f122f871717ed3d8926b1c87b2d64d2e4ff7d592354b4b88313870200000000ffffffff02a4c10000000000001600140020cfc65678c741e940384e89ea91cbb1f4b87687ea1c00000000001600145e1b68ebffea5e3db8093b9ec3fb06cefe733bf602483045022100a7653ea13f6b724c8d4f29efc58223540e7bb4ca6c48f2bef50e19389b98298702205febdf29158e107cb270272734d2aa31ef0eb8655854a920b412cf7b9924489d0121020589695f84721a19a98556b9ca4c313543d367a01297b71bb730c4c78235745a00000000020000000001018ddb375228be60ea4c2576313889c0a451dd7dd4411921116602a410b87015ff0100000000ffffffff02b3c10000000000001600140020dd6eaf53433629dafe3309521184efd51e89b4271c00000000001600143c7d2a0e9161c714c025a2a077ebd3594bc0d94c024730440220624759030b982f2a4a916dd13b5442910fe97db1626abf0950469c267fec432502202a07e8a7aa719984f1fa36783feaf829d791f5a8460aef55be7ae0e25edd872a012103d99c7c303fc602a6698fdb52cba92893b32f611e35c340944bb8ffb6c6eb63cd0000000002000000000101a76bca6b13d0771803d6f7e555ffe0a6295eaddb3a3855edba77f447b8bb2ba74100000000ffffffff02e5250000000000001600147bdf358b91ee6bc5394e43912038abf90209676bfc01000000000000160014a03039accfcf5fe17d498fea98f7d25b918024c70248304502210089a64f1936774a6e674327a68d8f157c584dde6e4515d1439c731b1362e06fdf02201f50c747b4c3817103c1ba9de2c98ebe9249ef9247494d4aa75ed7b030a54ea001210340f2590f254a903691b2ec6569440bb3c530c108d0a31743abf6532ec291c0d100000000020000000001016c93d8297e79503f91b075efa1a8c4398069f4f2e318fee4ff4c8257b40125f7010000001716001488eb816265625104ef1b9738362a2a0db9775572fdffffff02d0640700000000001600146ed37d9299675539f43e8f24581dadf5ab09bfae1cfe08000000000017a914ab6bfa2212fe8fde187034f32f16a2fd5b2565b9870247304402200a4c831505544a6c9aa0106e023115334d34903dc67b0e47fe02f85adc51beaa022035f9d84a69f2c88acf3ad7d941d21b1a65a52fd0a8ec69f61ecd6eab7277277401210231a0e1d7c13b183c936025267d1abb54eafcb425d4bd25aa4e0e948b0c438d80445c0b00020000000001019f3b0c8bdc9cd3f73cecfe29b79bd5e1b3f2ab800572258b35521a613dd5653e0100000000ffffffff02447900000000000017a91427f0ecde5e857f7464bce18a9b3e20bf7e270cdb8778010000000000001600140fefec68e9c033dd0ec567961fc97e13738e053d0247304402206d6c1ba4dd5e9a53436ce19ca9fdecc185b76406162efd9365d70903403e2ec4022071a31979e687978db1aa215e55a8381d566554342224690ce5c795d5a6bb01fa012103f5062c030b4a868548844c909b75748b2ed1825ee364bc338f682c436eb4fac000000000020000000001010dd140e1cbd31a6b52e896538faf5a0db92b212d7fec2207c916706d57bee2a05800000000ffffffff0237ad02000000000017a914579c355343865e5254063550adf82404465eee4f87e00a00000000000016001453028bb0e5f9cd92c4e2db29bdf16bb8c1ac669302473044022060a2c8c3581f2951f715b504317bd2953f3897e31a5daf8ac0630ae595d85959022028afc665c079b4b5f2ae6d11c1815661316baf918025b083f517e59891fa5e43012102fab960033dc9b588c08d011e5dea59c56ef310e857bf3b98fee48ac389e4276300000000020000000001018b146b0b9b864e24d69c7fa21eabe33532ddb76b479033503bd1e664d3a123940000000000ffffffff02eb4988010000000017a914f4a63ac3be00a88eef64fb6717d7f2922d6f76dc87f410010000000000160014e0091501e40b63ec71fe342582799006f3aa92a602473044022050c4539cca66ebbbf191a611b061f97c99500460eed5f92d8de5a14f5e83c09e02201fea301c9642bab11daa7297088dbedd22cddf709187e1ec52eef12aa5cb0e64012102531d2b99e94432aa0e771f9885aec22097a79de5ec8dbe8787832105aa7fa75c000000000200000000010176e7d1b947926d08e8f109cbb21007e8b8f450a696772233bbd9eaf581ab2c0c0100000000ffffffff02bd5e00000000000017a914c1c62e8551f0bdd55adeea1cd7e4d68383df474087d26a030000000000160014ee7efe9bcf23564f2008226e7a5767f3c31ada6202473044022045718d3bcf494179c48699cb319d579ddd9021c1c5dc286f577970ebfe171093022051867fcda8a248bbe07b8563038b2d2508f1bb9e7a ``` -------------------------------- ### Initialize HD Wallet from Mnemonic Source: https://context7.com/karask/python-bitcoin-utils/llms.txt Sets up the Bitcoin network (e.g., testnet) and initializes an HDWallet object from a BIP-39 mnemonic phrase. The `setup()` function must be called before creating the HDWallet. ```python from bitcoinutils.setup import setup from bitcoinutils.hdwallet import HDWallet setup("testnet") # Example usage (mnemonic not provided in source): # mnemonic = "" # hdwallet = HDWallet.from_mnemonic(mnemonic) ``` -------------------------------- ### Configure Bitcoin Network Source: https://context7.com/karask/python-bitcoin-utils/llms.txt Call `setup()` before using other functions to configure the active Bitcoin network. Supported values include mainnet, testnet, testnet4, signet, and regtest. ```python from bitcoinutils.setup import setup, get_network, set_security_warnings # Switch to testnet (default is "testnet") setup("testnet") print(get_network()) # "testnet" # Suppress pure-Python private-key warnings on mainnet setup("mainnet") set_security_warnings(False) # Use regtest for local node integration setup("regtest") ```