### Install Cryptos Library Source: https://context7.com/beppe1988/pybitcointools/llms.txt Install the cryptos library using pip. This command is used to add the library to your Python environment. ```bash pip install cryptos ``` -------------------------------- ### privtop2w - Get SegWit Address from Private Key Source: https://context7.com/beppe1988/pybitcointools/llms.txt Creates a pay-to-witness-public-key-hash (P2WPKH) address from a private key. This is used for SegWit transactions that reduce fees through witness data segregation. ```APIDOC ## privtop2w - Get SegWit Address from Private Key ### Description Creates a pay-to-witness-public-key-hash (P2WPKH) address from a private key. This is used for SegWit transactions that reduce fees through witness data segregation. ### Method `privtop2w(private_key)` ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from cryptos import * coin = Litecoin(testnet=True) priv = sha256('a big long brainwallet password') segwit_addr = coin.privtop2w(priv) # Output: '2Mtj1R5qSfGowwJkJf7CYufFVNk5BRyAYZh' ``` ### Response #### Success Response (200) - **segwit_addr** (string) - The generated SegWit address. ``` -------------------------------- ### privtopub - Get Public Key from Private Key Source: https://context7.com/beppe1988/pybitcointools/llms.txt Derives the public key from a private key using elliptic curve cryptography (secp256k1). Supports multiple input/output formats including hex, WIF, and binary. ```APIDOC ## privtopub - Get Public Key from Private Key ### Description Derives the public key from a private key using elliptic curve cryptography (secp256k1). Supports multiple input/output formats including hex, WIF, and binary. ### Method `privtopub(private_key)` ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from cryptos import * coin = Bitcoin(testnet=True) priv = sha256('a big long brainwallet password') # Output: '89d8d898b95addf569b458fbbd25620e9c9b19c9f730d5d60102abbabcb72678' pub = coin.privtopub(priv) # Output: '041f763d81010db8ba3026fef4ac3dc1ad7ccc2543148041c61a29e883ee4499dc724ab2737afd66e4aacdc0e4f48550cd783c1a73edb3dbd0750e1bd0cb03764f' ``` ### Response #### Success Response (200) - **pub** (string) - The derived public key in hex format. ``` -------------------------------- ### Get Unspent Transaction Outputs (UTXOs) Source: https://context7.com/beppe1988/pybitcointools/llms.txt Retrieves unspent transaction outputs for a given address. Use the --testnet flag for testnet operations and --coin for specific cryptocurrencies. ```bash cryptotool unspent 2N8hwP1WmJrFF5QWABn38y63uYLhnJYJYTF --testnet ``` ```bash cryptotool unspent LV3VLesnCi3p3zf26Y86kH2FZxfQq2RjrA --coin ltc ``` -------------------------------- ### Create BIP39 Standard HD Wallet Source: https://context7.com/beppe1988/pybitcointools/llms.txt Initializes a hierarchical deterministic wallet using BIP44 derivation paths. ```python from cryptos import * words = 'practice display use aisle armor salon glue okay sphere rather belt mansion' coin = Bitcoin() wallet = coin.wallet(words) # Derivation path: m/44'/0'/0' # Access extended keys print(wallet.keystore.root_derivation) # "m/44'/0'/0'" print(wallet.keystore.xprv) # Account Extended Private Key print(wallet.keystore.xpub) # Account Extended Public Key # Generate addresses addr1 = wallet.new_receiving_address() # Output: '18q3EiCiKd5vydnaVwWEpAFyzfL2ftAZ1L' addr2 = wallet.new_change_address() # Output: '1BgkpwEDrTbCNduyR97EpW4zvFhEzWsyvi' # Get private key for an address privkey = wallet.privkey(addr1) # Output: 'L4cKz3epcM3CAmwkSwJwZ2c4q5ukmSVWCrE9PqE46ybU3XyzfTYx' ``` -------------------------------- ### history - Get Transaction History Source: https://context7.com/beppe1988/pybitcointools/llms.txt Retrieves the transaction history and balance for one or more addresses from the blockchain explorer. ```APIDOC ## history - Get Transaction History ### Description Retrieves the transaction history and balance for one or more addresses from the blockchain explorer. ### Method `history(address)` ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from cryptos import * coin = Bitcoin() addr = '1CQLd3bhw4EzaURHbKCwM5YZbUQfA4ReY6' history = coin.history(addr) # Returns list of transactions with outputs and values ``` ### Response #### Success Response (200) - **history** (list) - A list of transaction objects associated with the address. ``` -------------------------------- ### Generate BIP39-BIP49 Segwit Bitcoin Wallet and Addresses Source: https://github.com/beppe1988/pybitcointools/blob/master/README.md Creates a BIP39 compatible Bitcoin wallet using the BIP49 derivation path for Segwit (P2WPKH-P2SH) addresses. Shows how to obtain the root derivation path, extended private and public keys, and generate receiving and change addresses with their private keys. ```python from cryptos import * words = entropy_to_words(os.urandom(20)) print(words) print(keystore.bip39_is_checksum_valid(words)) coin = Bitcoin() wallet = coin.p2wpkh_p2sh_wallet(words) print(wallet.keystore.root_derivation) print(wallet.keystore.xprv) #Account Extended Private Key print(wallet.keystore.xpub) # Account Extended Public Key addr1 = wallet.new_receiving_address() print(addr1) print(wallet.privkey(addr1)) addr2 = wallet.new_change_address() print(addr2) print(wallet.privkey(addr2)) addr3 = wallet.new_change_address() print(addr3) print(wallet.privkey(addr3)) ``` -------------------------------- ### Generate P2WPKH Address and Create Segwit Transaction Source: https://github.com/beppe1988/pybitcointools/blob/master/README.md This snippet shows the manual process of creating a Segwit transaction. It involves generating a P2WPKH address, marking UTXOs as segwit, constructing the transaction, signing it, and serializing it for broadcasting. Ensure testnet is used for practice. ```python from cryptos import * c = Litecoin(testnet=True) priv = sha256('a big long brainwallet password') addr = c.privtop2w(priv) inputs = c.unspent(addr) inputs[0]['segwit']=True outs = [{'value': 79956800, 'address': 'mxYcACPJWAMMkXu7S9SM8npicFWehpYCWx'}, {'value': 19989200, 'address': '2Mtj1R5qSfGowwJkJf7CYufFVNk5BRyAYZh'}] tx = c.mktx(inputs,outs) tx2 = c.sign(tx,0,priv) tx3 = serialize(tx) c.pushtx(tx3) ``` -------------------------------- ### Get Transaction History and Balance Source: https://context7.com/beppe1988/pybitcointools/llms.txt Retrieve the transaction history and balance for one or more addresses using the 'history' method. This queries a blockchain explorer. ```python from cryptos import * coin = Bitcoin() addr = '1CQLd3bhw4EzaURHbKCwM5YZbUQfA4ReY6' history = coin.history(addr) # Returns list of transactions with outputs and values ``` -------------------------------- ### pubtoaddr - Get Address from Public Key Source: https://context7.com/beppe1988/pybitcointools/llms.txt Converts a public key to a cryptocurrency address using hash160 (SHA256 + RIPEMD160) and base58check encoding. ```APIDOC ## pubtoaddr - Get Address from Public Key ### Description Converts a public key to a cryptocurrency address using hash160 (SHA256 + RIPEMD160) and base58check encoding. ### Method `pubtoaddr(public_key)` ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from cryptos import * coin = Bitcoin(testnet=True) priv = sha256('a big long brainwallet password') pub = coin.privtopub(priv) addr = coin.pubtoaddr(pub) # Output: 'mwJUQbdhamwemrsR17oy7z9upFh4JtNxm1' ``` ### Response #### Success Response (200) - **addr** (string) - The generated cryptocurrency address. ``` -------------------------------- ### Initialize Coin Objects Source: https://context7.com/beppe1988/pybitcointools/llms.txt Initialize coin objects for various cryptocurrencies like Bitcoin, Litecoin, and Dash. Specify 'testnet=True' for testnet networks. ```python from cryptos import * # Initialize coin objects btc = Bitcoin() btc_testnet = Bitcoin(testnet=True) ltc = Litecoin() bch = BitcoinCash() dash = Dash() doge = Doge() btg = BitcoinGold() ``` -------------------------------- ### privtoaddr - Get Address from Private Key Source: https://context7.com/beppe1988/pybitcointools/llms.txt Converts a private key directly to a cryptocurrency address. The address format is determined by the coin's magic byte configuration. ```APIDOC ## privtoaddr - Get Address from Private Key ### Description Converts a private key directly to a cryptocurrency address. The address format is determined by the coin's magic byte configuration. ### Method `privtoaddr(private_key)` ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from cryptos import * priv = sha256('a big long brainwallet password') # Bitcoin mainnet address b = Bitcoin() addr = b.privtoaddr(priv) # Output: '1GnX7YYimkWPzkPoHYqbJ4waxG6MN2cdSg' # Bitcoin testnet address b_test = Bitcoin(testnet=True) addr_test = b_test.privtoaddr(priv) # Output: 'mwJUQbdhamwemrsR17oy7z9upFh4JtNxm1' # Litecoin address l = Litecoin() addr_ltc = l.privtoaddr(priv) # Output: 'Lb1UNkrYrQkTFZ5xTgpta61MAUTdUq7iJ1' # Dash address d = Dash() addr_dash = d.privtoaddr(priv) # Output: 'XrUMwoCcjTiz9gzP9S9p9bdNnbg3MvAB1F' ``` ### Response #### Success Response (200) - **addr** (string) - The generated cryptocurrency address. ``` -------------------------------- ### Wallet Management Methods Source: https://github.com/beppe1988/pybitcointools/blob/master/README.md Overview of available wallet creation and management methods provided by the library. ```APIDOC ## Wallet Methods ### Description The library provides several methods to initialize different types of wallets based on BIP39 or Electrum standards. ### Methods - **wallet**: BIP 39 Standard - **watch_wallet**: BIP 39 Standard, watch-only - **p2wpkh_p2sh_wallet**: BIP 39 Segwit P2SH addresses - **watch_p2wpkh_p2sh_wallet**: BIP 39 Segwit P2SH addresses, watch-only - **p2wpkh_wallet**: BIP 39 New Segwit Addresses - **watch_p2wpkh_wallet**: BIP New Segwit Address, watch-only - **electrum_wallet**: Detects p2kh or p2wpkh based on seed - **watch_electrum_wallet**: Watch electrum standard wallet - **watch_electrum_p2wpkh_wallet**: Watch electrum new segwit wallet ``` -------------------------------- ### unspent - Get Unspent Transaction Outputs Source: https://context7.com/beppe1988/pybitcointools/llms.txt Retrieves unspent transaction outputs (UTXOs) for one or more addresses. Returns a list of dictionaries containing the outpoint reference and value in satoshis. ```APIDOC ## unspent - Get Unspent Transaction Outputs ### Description Retrieves unspent transaction outputs (UTXOs) for one or more addresses. Returns a list of dictionaries containing the outpoint reference and value in satoshis. ### Method `unspent(address)` ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from cryptos import * coin = Bitcoin(testnet=True) addr = 'mwJUQbdhamwemrsR17oy7z9upFh4JtNxm1' inputs = coin.unspent(addr) # Output: [ # {'output': '3be10a0aaff108766371fd4f4efeabc5b848c61d4aac60db6001464879f07508:0', 'value': 180000000}, # {'output': '51ce9804e1a4fd3067416eb5052b9930fed7fdd9857067b47d935d69f41faa38:0', 'value': 90000000} # ] ``` ### Response #### Success Response (200) - **inputs** (list) - A list of dictionaries, where each dictionary represents a UTXO with 'output' (txid:vout) and 'value' (in satoshis). ``` -------------------------------- ### Create Watch-Only Wallet Source: https://context7.com/beppe1988/pybitcointools/llms.txt Initializes a wallet from an extended public key that can generate addresses but cannot sign transactions. ```python from cryptos import * coin = Dash() xpub = 'xpub6ChohEsxBkvi17xRrtTEPYcyb8dRKLzjQs5Lsc9NHzhmFQARJZFaeuqxtEMHaF4J8MzatWSYrmq2qAc3BaxFiKzEwX1AKQx5uWHZr3y8s82' wallet = coin.watch_wallet(xpub) print(wallet.is_watching_only) # True # Generate addresses addr1 = wallet.new_receiving_address() # Output: 'Xea1GEenz6Toq5YQjvjz86MTT8ezT5ZwnY' addr2 = wallet.new_change_address() # Output: 'XwYCR4CwafwoGe6P4H9LndaqAQkmE6xYix' # Cannot get private keys from watch-only wallet privkey = wallet.privkey(addr1) # Returns None ``` -------------------------------- ### Prepare and Push Signed Transactions Source: https://github.com/beppe1988/pybitcointools/blob/master/README.md Manually prepare a signed transaction and push it to the network for verification. ```python from cryptos import * dash = Dash() tx = dash.preparesignedtx(priv, "Xhcmzs5wKECBiWwSEsTZu8wNonguH5poaz", 9800000-20000, fee=20000) tx '010000000194f2f955627dfd549f213a70d65dcd5550c0b14a484d38b6ae47fe7a8896ca41000000008b483045022100b125b1f4848c145193f70b915b0074539d90fd74c2e75492169f06927acafa39022025a009711a354a7d84e19f234dfb5d20e155b64acad40941670e634c1100101a01410437b81f8f1376a87556380ad9f3a6b7f642754b3497ce42518f8dbd39bfedea24d897ae5d8d1dd41c04f55700ed6f3b7cee99df5aed74f98a54cbc576d75c0b9fffffffff01203b9500000000001976a9144c0404140e6ad8d04bdf625888bf6dfcc20fa12d88ac00000000' dash.pushtx(tx) {'status': 'success', 'data': {'txid': '0d889f6a268340c8fd30cdc6567eb588765e911fdd1fb0aac870dc3125ffde76', 'network': 'DASH'}} ``` ```python from cryptos import * crypto = BitcoinCash(testnet=True) tx = crypto.preparesignedtx("89d8d898b95addf569b458fbbd25620e9c9b19c9f730d5d60102abbabcb72678", "mgRoeWs2CeCEuqQmNfhJjnpX8YvtPACmCX", 967916800) tx '010000000144ea7b41df09cee54c43f817dc11fd4d88c9b721b4c13b588f6a764eab78f692000000008b4830450221008efa819db89f714dbe0a19a7eb605d03259f4755a0f12876e9dddf477e1867b8022072bc76d120e92668f4765b5d694aee4a3cafd6cd4aaa8d5ebf88c3f821c81d9c4141041f763d81010db8ba3026fef4ac3dc1ad7ccc2543148041c61a29e883ee4499dc724ab2737afd66e4aacdc0e4f48550cd783c1a73edb3dbd0750e1bd0cb03764fffffffff02003db139000000001976a91409fed3e08e624b23dbbacc77f7b2a39998351a6888acf046df07000000001976a914ad25bdf0fdfd21ca91a82449538dce47f8dc213d88ac00000000' crypto.pushtx(tx) {'status': 'success', 'data': {'txid': 'd8b130183824d0001d3bc669b31e798e2654868a7fda743aaf35d757d89db0eb', 'network': 'tbcc'}} ``` -------------------------------- ### wallet Source: https://context7.com/beppe1988/pybitcointools/llms.txt Creates a BIP39 standard HD wallet. ```APIDOC ## wallet ### Description Creates a hierarchical deterministic wallet from a BIP39 mnemonic seed following BIP44 derivation paths. ### Method coin.wallet(words) ### Parameters - **words** (string) - Required - BIP39 mnemonic phrase ``` -------------------------------- ### Get Unspent Transaction Outputs (UTXOs) Source: https://context7.com/beppe1988/pybitcointools/llms.txt Retrieve unspent transaction outputs (UTXOs) for a given address using the 'unspent' method. Returns a list of UTXO details including output and value. ```python from cryptos import * coin = Bitcoin(testnet=True) addr = 'mwJUQbdhamwemrsR17oy7z9upFh4JtNxm1' inputs = coin.unspent(addr) # Output: [ # {'output': '3be10a0aaff108766371fd4f4efeabc5b848c61d4aac60db6001464879f07508:0', 'value': 180000000}, # {'output': '51ce9804e1a4fd3067416eb5052b9930fed7fdd9857067b47d935d69f41faa38:0', 'value': 90000000} # ] ``` -------------------------------- ### Construct and Sign a Bitcoin Transaction Source: https://github.com/beppe1988/pybitcointools/blob/master/README.md This sequence shows the manual workflow for creating a transaction on the testnet, from generating a private key to signing the transaction inputs. ```python > from cryptos import * > c = Bitcoin(testnet=True) > priv = sha256('a big long brainwallet password') > priv '89d8d898b95addf569b458fbbd25620e9c9b19c9f730d5d60102abbabcb72678' > pub = c.privtopub(priv) > pub '041f763d81010db8ba3026fef4ac3dc1ad7ccc2543148041c61a29e883ee4499dc724ab2737afd66e4aacdc0e4f48550cd783c1a73edb3dbd0750e1bd0cb03764f' > addr = c.pubtoaddr(pub) > addr 'mwJUQbdhamwemrsR17oy7z9upFh4JtNxm1' > inputs = c.unspent(addr) > inputs [{'output': '3be10a0aaff108766371fd4f4efeabc5b848c61d4aac60db6001464879f07508:0', 'value': 180000000}, {'output': '51ce9804e1a4fd3067416eb5052b9930fed7fdd9857067b47d935d69f41faa38:0', 'value': 90000000}] > outs = [{'value': 269845600, 'address': '2N8hwP1WmJrFF5QWABn38y63uYLhnJYJYTF'}, {'value': 100000, 'address': 'mrvHv6ggk5gFMatuJtBKAzktTU1N3MYdu2'}] > tx = c.mktx(inputs,outs) > tx {'locktime': 0, 'version': 1, 'ins': [{'outpoint': {'hash': '3be10a0aaff108766371fd4f4efeabc5b848c61d4aac60db6001464879f07508', 'index': 0}, 'amount': 180000000, 'script': '483045022100fccd16f619c5f8b8198f5a00f557f6542afaae10b2992733963c5b9c4042544c022041521e7ab2f4b58856e8554c651664af92f6abd58328c41bc652aea460a9a6a30141041f763d81010db8ba3026fef4ac3dc1ad7ccc2543148041c61a29e883ee4499dc724ab2737afd66e4aacdc0e4f48550cd783c1a73edb3dbd0750e1bd0cb03764f', 'sequence': 4294967295}, {'outpoint': {'hash': '51ce9804e1a4fd3067416eb5052b9930fed7fdd9857067b47d935d69f41faa38', 'index': 0}, 'amount': 90000000, 'script': '483045022100a9f056be75da4167c2cae9f037e04f6efd20caf97e05052406c127d72e7f236c02206638c10ad6975b44c26633e7c40547405dd4e6184fa3afd0ec98260369fadb0d0141041f763d81010db8ba3026fef4ac3dc1ad7ccc2543148041c61a29e883ee4499dc724ab2737afd66e4aacdc0e4f48550cd783c1a73edb3dbd0750e1bd0cb03764f', 'sequence': 4294967295}], 'outs': [{'script': 'a914a9974100aeee974a20cda9a2f545704a0ab54fdc87', 'value': 269845600}, {'script': '76a9147d13547544ecc1f28eda0c0766ef4eb214de104588ac', 'value': 100000}]} > tx2 = c.sign(tx,0,priv) > tx2 {'locktime': 0, 'version': 1, 'ins': [{'outpoint': {'hash': '3be10a0aaff108766371fd4f4efeabc5b848c61d4aac60db6001464879f07508', 'index': 0}, 'amount': 180000000, 'script': '483045022100fccd16f619c5f8b8198f5a00f557f6542afaae10b2992733963c5b9c4042544c022041521e7ab2f4b58856e8554c651664af92f6abd58328c41bc652aea460a9a6a30141041f763d81010db8ba3026fef4ac3dc1ad7ccc2543148041c61a29e883ee4499dc724ab2737afd66e4aacdc0e4f48550cd783c1a73edb3dbd0750e1bd0cb03764f', 'sequence': 4294967295}, {'outpoint': {'hash': '51ce9804e1a4fd3067416eb5052b9930fed7fdd9857067b47d935d69f41faa38', 'index': 0}, 'amount': 90000000, 'script': '483045022100a9f056be75da4167c2cae9f037e04f6efd20caf97e05052406c127d72e7f236c02206638c10ad6975b44c26633e7c40547405dd4e6184fa3afd0ec98260369fadb0d0141041f763d81010db8ba3026fef4ac3dc1ad7ccc2543148041c61a29e883ee4499dc724ab2737afd66e4aacdc0e4f48550cd783c1a73edb3dbd0750e1bd0cb03764f', 'sequence': 4294967295}], 'outs': [{'script': 'a914a9974100aeee974a20cda9a2f545704a0ab54fdc87', 'value': 269845600}, {'script': '76a9147d13547544ecc1f28eda0c0766ef4eb214de104588ac', 'value': 100000}]} > tx3 = c.sign(tx2,1,priv) > tx3 ``` -------------------------------- ### Create SegWit Address from Private Key Source: https://context7.com/beppe1988/pybitcointools/llms.txt Generate a P2WPKH SegWit address from a private key using 'privtop2w'. This is useful for reducing transaction fees. ```python from cryptos import * coin = Litecoin(testnet=True) priv = sha256('a big long brainwallet password') segwit_addr = coin.privtop2w(priv) # Output: '2Mtj1R5qSfGowwJkJf7CYufFVNk5BRyAYZh' ``` -------------------------------- ### Generate BIP39 Bitcoin Wallet and Addresses Source: https://github.com/beppe1988/pybitcointools/blob/master/README.md Generates a BIP39 compatible Bitcoin wallet from a mnemonic phrase. Shows how to derive the root derivation path, extended private and public keys, and generate new receiving and change addresses along with their private keys. Verifies address derivation using `privtoaddr`. ```python from cryptos import * words = entropy_to_words(os.urandom(16)) print(words) print(keystore.bip39_is_checksum_valid(words)) coin = Bitcoin() wallet = coin.wallet(words) print(wallet.keystore.root_derivation) print(wallet.keystore.xprv) #Account Extended Private Key print(wallet.keystore.xpub) # Account Extended Public Key addr1 = wallet.new_receiving_address() print(addr1) print(wallet.privkey(addr1)) addr2 = wallet.new_change_address() print(addr2) print(wallet.privkey(addr2)) addr3 = wallet.new_change_address() print(addr3) priv3 = wallet.privkey(addr3) print(priv3) assert coin.privtoaddr(priv3) == addr3 ``` -------------------------------- ### Derive Addresses Across Supported Coins Source: https://github.com/beppe1988/pybitcointools/blob/master/README.md Shows how to derive addresses from a private key for various cryptocurrencies and testnet configurations. ```python from cryptos import * priv = sha256('a big long brainwallet password') b = Bitcoin() b.privtoaddr(priv) '1GnX7YYimkWPzkPoHYqbJ4waxG6MN2cdSg' b = Bitcoin(testnet=True) b.privtoaddr(priv) 'mwJUQbdhamwemrsR17oy7z9upFh4JtNxm1' l = Litecoin() l.privtoaddr(priv) 'Lb1UNkrYrQkTFZ5xTgpta61MAUTdUq7iJ1' l = Litecoin(testnet=True) l.privtoaddr(priv) 'mwJUQbdhamwemrsR17oy7z9upFh4JtNxm1' c = BitcoinCash() c.privtoaddr(priv) '1GnX7YYimkWPzkPoHYqbJ4waxG6MN2cdSg' c = BitcoinCash(testnet=True) c.privtoaddr(priv) 'mwJUQbdhamwemrsR17oy7z9upFh4JtNxm1' d = Dash() d.privtoaddr(priv) 'XrUMwoCcjTiz9gzP9S9p9bdNnbg3MvAB1F' d = Dash(testnet=True) d.privtoaddr(priv) 'yc6xxkH4B1P4VRuviHUDBd3j4tAQpy4fzn' d = Doge() d.privtoaddr(priv) 'DLvceoVN5AQgXkaQ28q9qq7BqPpefFRp4E' bg = BitcinGold() bg.privtoaddr(priv) 'GZdSXfsfkc7h5Dh6DVVhiqHUsRtCMQ9fxG' bg = BitcoinGold(legacy=True) bg.privtoaddr(priv) '1GnX7YYimkWPzkPoHYqbJ4waxG6MN2cdSg' bg = BitcoinGold(testnet=True) bg.privtoaddr(priv) 'mwJUQbdhamwemrsR17oy7z9upFh4JtNxm1' ``` -------------------------------- ### Testnet and Multi-coin Support Source: https://github.com/beppe1988/pybitcointools/blob/master/README.md Use --testnet and --coin flags to interact with different blockchain networks and assets. ```bash cryptotool unspent 2N8hwP1WmJrFF5QWABn38y63uYLhnJYJYTF --testnet [{"output": "209e5caf8997a3caed4dce0399804ad7fa50c70f866bb7118a42c79de1b76efc:1", "value": 120000000}, {"output": "79f38b3e730eea0e44b5a2e645f0979 2d9f8732a823079ba4778110657cbe7b2:0", "value": 100000000}, {"output": "99d88509d5f0e298bdb6883161c64c7f54444519ce28a0ef3d5942ff4ff7a924:0", "value ": 82211600}, {"output": "80acca12cf4b3b562b583f1dc7e43fff936e432a7ed4b16ac3cd10024820d027:0", "value": 192470000}, {"output": "3e5a3fa342c767d524b653aec51f3efe2122644c57340fbf5f79c75d1911ad35:0", "value": 10000000}] ``` ```bash cryptotool unspent LV3VLesnCi3p3zf26Y86kH2FZxfQq2RjrA --coin ltc [{"output": "42bfe7376410696e260b2198f484f5df4aa6c744465940f9922ac9f8589670a4:0", "value": 14282660}] ``` ```bash cryptotool unspent myLktRdRh3dkK3gnShNj5tZsig6J1oaaJW --coin ltc --testnet [{"output": "68f9c662503715a3baf29fe4b07c056b0bf6654dbdd9d5393f4d6a18225d0ff3:0", "value": 16333531}, {"output": "aa40041a1fcdb952d6a38594a27529f890d17d715fd54b6914cd6709fa94ca67:0", "value": 100000000}, {"output": "3b72bae956d27ab0ad309808ab76beaf203109f423e533fd7c40f1201672f598:1", "value": 164712303}] ``` -------------------------------- ### Coin Initialization Source: https://context7.com/beppe1988/pybitcointools/llms.txt Initialize coin objects for various cryptocurrencies and network types (mainnet/testnet). ```APIDOC ## Coin Initialization ### Description Initialize coin objects for various cryptocurrencies and network types (mainnet/testnet). ### Method Instantiation ### Endpoint N/A ### Parameters None ### Request Example ```python from cryptos import * # Initialize coin objects btc = Bitcoin() btc_testnet = Bitcoin(testnet=True) ltc = Litecoin() bch = BitcoinCash() dash = Dash() doge = Doge() btg = BitcoinGold() ``` ### Response N/A ``` -------------------------------- ### Create Native SegWit Wallet (BIP84) Source: https://context7.com/beppe1988/pybitcointools/llms.txt Creates a native SegWit wallet using BIP84 derivation paths for bech32 addresses. ```python from cryptos import * words = 'jealous silver churn hedgehog border physical market parent hungry design cage lab drill clay attack' coin = Bitcoin() wallet = coin.p2wpkh_wallet(words) # Derivation path: m/84'/0'/0' print(wallet.keystore.xprv) # Output: 'zprvAcSKXVdgJHh5vyEeC6HSVScUCHxrKEWkkFSE2YsLpTborr4y2rHMrmr66yvxkGVqiiwwUCqUVkPB7o5ThnK3Dybi5PEywikXbNKQcHNMYPd' addr = wallet.new_receiving_address() # Output: 'bc1qkh6wwkyhfceuxq236pc9gtv2agfqnelzh5m94f' privkey = wallet.privkey(addr) # Output: 'Kwnaq7cvD4CAnTcppou6wpUpMFx5yZRqkpZcy6bBvPVKp2FQzJNf' ``` -------------------------------- ### Create SegWit P2SH Wallet (BIP49) Source: https://context7.com/beppe1988/pybitcointools/llms.txt Creates a SegWit wallet using BIP49 derivation paths for P2SH-wrapped addresses. ```python from cryptos import * words = 'jealous silver churn hedgehog border physical market parent hungry design cage lab drill clay attack' coin = Bitcoin() wallet = coin.p2wpkh_p2sh_wallet(words) # Derivation path: m/49'/0'/0' print(wallet.keystore.xprv) # Output: 'yprvAHoU8z6164hTNdwpArPgn2bdNExmUu9HwxeyhUok8pLDNQSCzYo8rvD6tFvMKk4EQXF2UGzRea5FBHjrtcuYmuBB7Z6EoznKCPeUwXaZduB' addr = wallet.new_receiving_address() # Output: '38yA1L6u6NiADrafrqZKDt1fTRHpGC3E7g' privkey = wallet.privkey(addr) # Output: 'Ky13njnYGrj5jowjUarqcmaRCG37zSwqRJkTj296cQsSvFtsV5a5' ``` -------------------------------- ### Create Unsigned Transaction Source: https://context7.com/beppe1988/pybitcointools/llms.txt Create an unsigned transaction using 'mktx' with specified inputs and outputs. For SegWit inputs, set 'segwit=True'. The difference between input and output values is the miner fee. ```python from cryptos import * coin = Bitcoin(testnet=True) # Define inputs (UTXOs to spend) inputs = [ {'output': '3be10a0aaff108766371fd4f4efeabc5b848c61d4aac60db6001464879f07508:0', 'value': 180000000}, {'output': '51ce9804e1a4fd3067416eb5052b9930fed7fdd9857067b47d935d69f41faa38:0', 'value': 90000000} ] # Define outputs (destination addresses and amounts) # Example: Send 100000000 satoshis to '1BoatSLRHtKNngkdXEeobR76b53LETtpyT' # and 50000000 satoshis to a change address. # outputs = [ # ('1BoatSLRHtKNngkdXEeobR76b53LETtpyT', 100000000), # ('1cMh2jJk35f5xX9f5913a9b3a3a3a3a3a3', 50000000) # Change address # ] # Create the unsigned transaction # unsigned_tx = coin.mktx(inputs, outputs) ``` -------------------------------- ### Generate BIP39 Dash Wallet and Addresses Source: https://github.com/beppe1988/pybitcointools/blob/master/README.md Generates a BIP39 compatible Dash wallet using a predefined mnemonic phrase. Demonstrates derivation of the root derivation path, extended private and public keys, and generation of receiving and change addresses with their corresponding private keys. Includes verification of address derivation. ```python from cryptos import * words = 'practice display use aisle armor salon glue okay sphere rather belt mansion' coin = Dash() wallet = coin.wallet(words) print(wallet.keystore.root_derivation) print(wallet.keystore.xprv) #Account Extended Private Key print(wallet.keystore.xpub) # Account Extended Public Key addr1 = wallet.new_receiving_address() print(addr1) print(wallet.privkey(addr1)) addr2 = wallet.new_change_address() print(addr2) print(wallet.privkey(addr2)) addr3 = wallet.new_change_address() print(addr3) priv3 = wallet.privkey(addr3) print(priv3) assert coin.privtoaddr(priv3) == addr3 ``` -------------------------------- ### p2wpkh_wallet Source: https://context7.com/beppe1988/pybitcointools/llms.txt Creates a native SegWit wallet (BIP84). ```APIDOC ## p2wpkh_wallet ### Description Creates a native SegWit wallet with bech32 addresses using BIP84 derivation path. ### Method coin.p2wpkh_wallet(words) ### Parameters - **words** (string) - Required - BIP39 mnemonic phrase ``` -------------------------------- ### Create and Sign a 2-of-3 MultiSig Transaction Source: https://github.com/beppe1988/pybitcointools/blob/master/README.md Demonstrates generating a multi-signature address from public keys and signing a transaction using multiple private keys. ```python from cryptos import * coin = Bitcoin(testnet=True) publickeys = ['02e5c473c051dae31043c335266d0ef89c1daab2f34d885cc7706b267f3269c609', '0391ed6bf1e0842997938ea2706480a7085b8bb253268fd12ea83a68509602b6e0', '0415991434e628402bebcbaa3261864309d2c6fd10c850462b9ef0258832822d35aa26e62e629d2337e3716784ca6c727c73e9600436ded7417d957318dc7a41eb'] script, address = coin.mk_multsig_address(publickeys, 2) script '522102e5c473c051dae31043c335266d0ef89c1daab2f34d885cc7706b267f3269c609210391ed6bf1e0842997938ea2706480a7085b8bb253268fd12ea83a68509602b6e0410415991434e628402bebcbaa3261864309d2c6fd10c850462b9ef0258832822d35aa26e62e629d2337e3716784ca6c727c73e9600436ded7417d957318dc7a41eb53ae' address '2ND6ptW19yaFEmBa5LtEDzjKc2rSsYyUvqA' tx = coin.preparetx(address, "myLktRdRh3dkK3gnShNj5tZsig6J1oaaJW", 1100000, 50000) for i in range(0, len(tx['ins'])): sig1 = coin.multisign(tx, i, script, "cUdNKzomacP2631fa5Q4yHv2fADc8Ueymr5Z5NUSJjVM13igcVJk") sig3 = coin.multisign(tx, i, script, "cMrziExc6iMV8vvAML8QX9hGDP8zNhcsKbdS9BqrRa1b4mhKvK6f") tx = apply_multisignatures(tx, i, script, sig1, sig3) tx '0100000001e62c0b5434108607f52856bfbcf5093363fbd4789141a661a4c6c8042769ed2001000000fd1d0100483045022100dfc75916f6bb5c5b72a45dea44dbc45b47ba90912efb84680a373acadb3b1212022022dbbd66e4871624609d875bdb592d11335eb4ec49c7b87bb0b8bc76f72f80f30147304402204c38cab196ec0e82a9f65ecba70a0dbf73f49e5886e1000b9bc52894e28fa5c9022007bff3f90bcece19036625806d4d1951a03c256627163f1ac4e76a6ee8eae072014c89522102e5c473c051dae31043c335266d0ef89c1daab2f34d885cc7706b267f3269c609210391ed6bf1e0842997938ea2706480a7085b8bb253268fd12ea83a68509602b6e0410415991434e628402bebcbaa3261864309d2c6fd10c850462b9ef0258832822d35aa26e62e629d2337e3716784ca6c727c73e9600436ded7417d957318dc7a41eb53aeffffffff02e0c81000000000001976a914c384950342cb6f8df55175b48586838b03130fad88ac301224030000000017a914d9cbe7c2c507c306f4872cf965cbb4fe51b621998700000000' coin.pushtx(tx) {'status': 'success', 'data': {'txid': 'b64e19311e3aa197063e03657679e2974e04c02c5b651c4e8d55f428490ab75f', 'network': 'BTCTEST'}} ```