https://github.com/bitcoinbook/bitcoinbook/blob/second_edition/code/pycoin_example.py
From Pycoin.key Import key to Pycoin.key.validate import Is_address_valid, is_wif_valid from pycoin.services import spe Ndables_for_address from pycoin.tx.tx_utils import Create_signed_tx def get_address (which): While 1:print ("
Enter the%s address=> "% which, end= ') address = input () Is_valid = Is_address_valid (address) If Is_valid:return address print ("Invalid address, please try again") Src_address = Get_address (" SOURCE ") Spendables = spendables_for_address (src_address) print (spendables) while 1:print (" Enter the WIF for%s=> "% src_address, end= ') wif = input () Is_valid = Is_wif_valid (wif) if is_valid:break print (" Inv Alid wif, please try again ") Key = Key.from_text (wif) if src_address not in (key.address), key. Address (Use_uncompressed=true): Print ("* * WIF doesn ' t correspond to%s"% src_address) print ("The Secret exponent is %d "% Key.secret_exponenT ()) dst_address = get_address ("destination") tx = Create_signed_tx (Spendables, payables=[dst_address], wifs=[wif]) pri
NT ("Here is the signed output transaction") Print (Tx.as_hex ())