edgecase
Author: StJohn Piano
Published: 2020-09-11
Datafeed Article 173
This article has been digitally signed by Edgecase Datafeed.
This article has been digitally signed by its author.
7083 words - 2851 lines - 72 pages




GOAL



Create and sign a Bitcoin transaction with two inputs and two outputs. Add it to the Bitcoin blockchain.




CONTENTS



- Goal
- Contents
- Brief Summary
- Project Plan
- Notes
- Project Log




BRIEF SUMMARY



Carried out Project Plan successfully.






PROJECT PLAN



Outline:
- In transaction T1, transfer bitcoin from an online exchange account to address A1.
- In transaction T2, transfer bitcoin from A1 to addresses A2 and A3.
- In transaction T3, transfer bitcoin from A2 and A3 to addresses A4 and A5. Creating transaction T3 is the goal of this project.
- In transaction T4, transfer bitcoin from A4 and A5 to address A6.
- In transaction T5, transfer bitcoin from A6 back to the online exchange account.


Details:
- Use Edgecase Bitcoin Storage Toolset version 2 (EBSTv2) to generate 6 Bitcoin private keys.
- Use EBSTv2 to derive addresses A1-A6 from these private keys.
- Estimate the transaction fees required for transactions T2-T5.
- Use bitcoinfees.earn.com to look up current Bitcoin transaction fee rates. Choose an amount to transfer in transaction T1. This amount should be significantly greater than the estimated total transaction fees, so that some tolerance is available for changes in the fee rate during the project.
- Use my Solidi account to transfer this amount of bitcoin to A1. This is transaction T1.
- Use EBSTv2 to create the transactions T2-T5. Wait for each to be mined before creating the next one.
- Use
http://blockchain.info/unspent?active={ADDRESS}
to look up the available UTXOs in a Bitcoin address.
- Use live.blockcypher.com/btc/decodetx to decode each transaction and confirm that it's formatted correctly.
- Use live.blockcypher.com/btc/pushtx to broadcast a signed transaction to the Bitcoin network.
- Use
http://live.blockcypher.com/btc/tx/{TXID}
to look up a transaction and see whether it's been mined.


Additional sub-goal: For transaction T2, deliberately create an initial version with a fee that is too low. It will not be mined. Broadcast a new version with a sufficiently high fee. These two versions will be a useful example for a new recipe for managing the fee and broadcast of a Bitcoin transaction.






NOTES



"UTXO" = Unspent Transaction Output


Financial information:
- Mined transactions all used a fee rate of 100 satoshi / byte.
- Current BTC/USD exchange rate: 1 BTC ~= 10500 USD.
- T1 sent 0.01 BTC (~105 USD) to address A1.
- T5 returned 0.00868200 BTC (~91.16 USD) to address A6.
- Actual transaction fees: 0.01 - 0.00868200 = 0.00131800 BTC (~13.84 USD)
- Actual total size of transactions T1-T5: 1321 bytes
- Estimated total size of transactions T1-T5: 1320 bytes
- Estimated total transaction fees: 1320 bytes * 100 satoshi / byte = 132000 satoshis
= 0.00132000 BTC (~13.86 USD)


Estimated transaction sizes:
T2: 257 bytes
T3: 437 bytes
T4: 403 bytes
T5: 223 bytes
Total: 1320 bytes

Actual transaction sizes:
T2: 258 bytes
T3: 438 bytes
T4: 402 bytes
T5: 223 bytes
Total: 1321 bytes















PROJECT LOG





Work machine:
- Name: Judgement
- Windows 10
- Windows Subsystem for Linux (WSL): Ubuntu 16.04
- I'm working in the WSL Ubuntu terminal.




First, download EBSTv2.
- Browse to Edgecase Bitcoin Storage Toolset version 2
- Scroll to the Downloadable Assets section.
- Download all the assets.

List of assets:
- bitcoin_functions_2.py
- bjorn_edstrom_ripemd160.py
- convert_dice_rolls_to_hex_bytes_3.py
- create_nonstandard_transaction_3.py
- create_transaction_3.py
- ecdsa-0.10.tar.gz
- generate_bitcoin_address_4.py
- nonstandard_bitcoin_functions_2.py
- nonstandard_transaction_3.py
- pypy_sha256.py
- transaction_3.py




Create a work directory. Move the EBSTv2 assets into it.



A Bitcoin private key is 32 random bytes. Generate 6 private keys using this recipe:
Recipe for generating entropy bytes using dice #2


Private key 1 (P1):
f6c8b60b49c35ef5e6e05e9b06aa5b2b28bd28fbfce696dfc2301347d494a22b


P2:
ecfb8057d4e053dda6849f6a361ca2d6797368651bbb2b52ce4691515a7909e1


P3:
fc8c7e92b44fe66f8f20d98a648f659da69461661673e22292a67dc20742ef17


P4:
f7def6819cf8efb7c4aeaddecb951688bcda37cee73b92f73a29be076e66579c


P5:
11717a85a51ba5cd1711905816a694bdd288d0639f27d8bb113ba94df9da1501


P6:
bdd04ba66229d390b565b3aec61ea7aef4863fac98b493d1c6c3e7c6e0d5e391




Using Recipe for generating a Bitcoin address #2, derive addresses A1-A6 from private keys P1-P6.


Address 1 (A1):
1BB66Gx4833uKx8Lo2k8Mt4TRk42WTr7cZ


A2:
12YCFdpsRDvEHNcj5rsmvJ5G2XXkW1icJP


A3:
1H5SUR7Fv7x252WuJPqBjewwpeHuJ218Ky


A4:
136oURWq1zjkdQHKcanE7TyA3o36ibARNM


A5:
12PX5jPyQYejyrU79nZUDmKXvB3ttMfDqZ


A6:
1LVenxwqnmvwjjBdyUByWsD7mXNmJJP2ZF






stjohn@judgement:work$ ls -1

bitcoin_functions_2.py
bjorn_edstrom_ripemd160.py
convert_dice_rolls_to_hex_bytes_3.py
create_nonstandard_transaction_3.py
create_transaction_3.py
dice_rolls.txt
ecdsa
ecdsa-0.10
ecdsa-0.10.tar.gz
generate_bitcoin_address_4.py
nonstandard_bitcoin_functions_2.py
nonstandard_transaction_3.py
pypy_sha256.py
transaction_3.py





Estimate the transaction fees required for transactions T2-T5.

In Bitcoin transaction test set, we have these transactions:

- Transaction 1 (223 bytes): 1 input, 1 output
- Transaction 2 (223 bytes): 1 input, 1 output
- Transaction 3 (257 bytes): 1 input, 2 outputs
- Transaction 4 (257 bytes): 1 input, 2 outputs
- Transaction 5 (403 bytes): 2 inputs, 1 output

Transaction 3 has 1 more output than Transaction 1 and has 257-223=34 more bytes. So I can estimate that each additional output adds ~34 bytes.

Transaction 5 has 1 more input than Transaction 1 and has 403-223=180 more bytes. So I can estimate that each additional input adds ~180 bytes.

Looking at the project outline, I see that:
- T1 will be made by the exchange.
- T2 will have 1 input and 2 outputs. Estimated byte size = 223 + 34 = 257.
- T3 will have 2 inputs and 2 outputs. Estimated byte size = 223 + 180 + 34 = 437.
- T4 will have 2 inputs and 1 output. Estimated byte size = 223 + 180 = 403.
- T5 will have 1 input and 1 output. Estimated byte size = 223.

Estimated total number of bytes = 257 + 437 + 403 + 223 = 1320




Next: Use bitcoinfees.earn.com to look up current Bitcoin transaction fee rates.

For inclusion in the next 2-10 blocks, the current fee rate is 100 satoshi / byte.

1320 bytes * 100 satoshi / byte = 132000 satoshis
= 0.00132000 bitcoin

At current BTC/USD exchange rate (1 BTC = ~10500 USD), this is 13.86 USD.



Choose an amount to transfer in transaction T1. This amount should be significantly greater than the estimated total transaction fees, so that some tolerance is available for changes in the fee rate during the project.

I'll transfer $100 worth of bitcoin. Currently, this is approximately 0.01 BTC.




Log on to Solidi. Buy 0.01 BTC for 77.42 GBP.


Use Solidi to transfer 0.01 BTC to address A1.
1BB66Gx4833uKx8Lo2k8Mt4TRk42WTr7cZ



Done. Txid:
9d64ba7c5afdb3caa79bb79c35dde09af70b27829241b2823e4ffb918c75d153





Use EBSTv2 to create transaction T2. Deliberately create an initial version with a fee that is too low. It will not be mined.

Recipe:
Recipe for creating and signing a standard Bitcoin transaction #2

I'll use a fee of 0 satoshis.
- Correction: Turns out there is a minimum fee required for nodes to accept a transaction for broadcast. I've done some reading but it's still not clear to me exactly what this minimum fee is or how it's calculated. I won't include the log data for this version of the transaction.

Next: I'll use a fee rate of 1 satoshi / byte.




A random 32 byte value ("K" value) is required for making the transaction input signature. Generate a random 32 byte value using this recipe: Recipe for generating entropy bytes using dice #2

K value 1 (K1):
63d8100aee909cf3bb8bf9039f577675e9e54ab9d8d811b1511a07602746c87a




Browse to
blockchain.info/unspent?active=1BB66Gx4833uKx8Lo2k8Mt4TRk42WTr7cZ
to get a list of the unspent output in address A1.

Result:
{"notice":"","unspent_outputs":[{"tx_hash":"53d1758c91fb4f3e82b2419282270bf79ae0dd359cb79ba7cab3fd5a7cba649d","tx_hash_big_endian":"9d64ba7c5afdb3caa79bb79c35dde09af70b27829241b2823e4ffb918c75d153","tx_output_n":0,"script":"76a9146f99aacb549f7d662e6f82476b572f824387d95488ac","value":1000000,"value_hex":"0f4240","confirmations":77,"tx_index":0}]}


Notes:
- "tx_hash_big_endian" is the txid.
- "tx_output_n" is the previous output index.

Hm. I'd like to automate the processing of this info.




[development occurs here]




getUTXOsInAddress.py

python 2.7
import argparse
import requests
import decimal
D = decimal.Decimal


def main():

	mainHelpMsg = """
A command-line tool that looks up the UTXOs (Unspent Transaction Outputs) in a particular Bitcoin address.
It queries blockchain.info.
"""

	parser = argparse.ArgumentParser(description=mainHelpMsg, formatter_class=argparse.RawTextHelpFormatter)
	parser.add_argument('-a', '--address', required=True, help='Address to look up')
	args = parser.parse_args()
	address = args.address
	
	utxos = getUTXOsInAddress(address)
	
	print 'address: ' + address
	for i, utxo in enumerate(utxos):
		print '- utxo {}:'.format(i)
		print '-- txid: ' + utxo['txid']
		print '-- previous_output_index: ' + utxo['previous_output_index']
		print '-- satoshiValue: ' + utxo['satoshiValue']
		print '-- bitcoinValue: ' + utxo['bitcoinValue']


def getUTXOsInAddress(address):
	url = 'http://blockchain.info/unspent?active='
	url += address
	timeToWait = 10 # seconds
	response = requests.get(url, timeout=timeToWait)
	result = response.json()
	# Example json output:
	# {u'notice': u'', u'unspent_outputs': [{u'tx_hash': u'53d1758c91fb4f3e82b2419282270bf79ae0dd359cb79ba7cab3fd5a7cba649d', u'script': u'76a9146f99aacb549f7d662e6f82476b572f824387d95488ac', u'value_hex': u'0f4240', u'tx_hash_big_endian': u'9d64ba7c5afdb3caa79bb79c35dde09af70b27829241b2823e4ffb918c75d153', u'tx_index': 0, u'value': 1000000, u'confirmations': 82, u'tx_output_n': 0}]}
	utxos = []
	for u in result['unspent_outputs']:
		if u['confirmations'] < 6:
			continue
		satoshiValue = u['value']
		bitcoinValue = D(satoshiValue) / D(10**8)
		utxo = {
			'txid': u['tx_hash_big_endian'],
			'previous_output_index': str(u['tx_output_n']),
			'satoshiValue': str(satoshiValue),
			'bitcoinValue': str(bitcoinValue),
		}
		utxos.append(utxo)
	return utxos


if __name__ == '__main__': main()







Now, use this tool to look up the UTXOs in address A1.


stjohn@judgement:work$ python getUTXOsInAddress.py --address 1BB66Gx4833uKx8Lo2k8Mt4TRk42WTr7cZ

address: 1BB66Gx4833uKx8Lo2k8Mt4TRk42WTr7cZ
- utxo 0:
-- txid: 9d64ba7c5afdb3caa79bb79c35dde09af70b27829241b2823e4ffb918c75d153
-- previous_output_index: 0
-- satoshiValue: 1000000
-- bitcoinValue: 0.01





Return to creating transaction T2. It will send the bitcoin in A1 to addresses A2 and A3.


I've set the controls in the tool create_transaction_3.py as shown below.


	##### START CONTROLS
	# Note: Hex characters in input variable values must be lowercase. 
	random_values = [
		"63d8100aee909cf3bb8bf9039f577675e9e54ab9d8d811b1511a07602746c87a",
	]
	# random_value must be between 1 and 32 bytes. If random_value_type is "raw_bytes", then random_value must be between 1 and 32 ASCII characters. If random_value_type is "hex_bytes", then random_value must be an even number of hex characters and between 2 and 64 hex characters (1 byte is represented by 2 hex characters). 
	# Note: Every ECDSA signature (one for each input in a transaction) requires new random entropy. 
	# random_value_type options: ["raw_bytes", "hex_bytes"]
	random_value_type = "hex_bytes"
	input_data = [
		{
		"txid": "9d64ba7c5afdb3caa79bb79c35dde09af70b27829241b2823e4ffb918c75d153",
		"previous_output_index": "0",
		"private_key_hex": "f6c8b60b49c35ef5e6e05e9b06aa5b2b28bd28fbfce696dfc2301347d494a22b",
		#"satoshi_amount": "", 
		"bitcoin_amount": "0.01", 
		},
	]
	output_data = [
		{
		"address": "12YCFdpsRDvEHNcj5rsmvJ5G2XXkW1icJP",
		#"satoshi_amount": "", 
		"bitcoin_amount": "0.005", 
		},
		{
		"address": "1H5SUR7Fv7x252WuJPqBjewwpeHuJ218Ky",
		#"satoshi_amount": "", 
		"bitcoin_amount": "0.005", 
		},
	]
	# note: all inputs and outputs are assumed to be Pay-To-Public-Key-Hash (P2PKH). 
	change_address = "12YCFdpsRDvEHNcj5rsmvJ5G2XXkW1icJP"
	# note: the fee will be subtracted from the amount that is being sent to the change address.
	fee = "" # satoshi
	fee_rate = "1" # satoshi / byte
	# fee_type options: ["fee", "fee_rate"]
	fee_type = "fee_rate"
	##### END CONTROLS





Create and sign the transaction.


stjohn@judgement:work$ python create_transaction_3.py


### START CREATION OF BITCOIN TRANSACTION

- Fee type: fee_rate
- Fee rate: 1.0 (satoshi / byte)
- Number of inputs (i.e. as-yet-unspent outputs): 1
- Number of outputs: 2
- Change address: 12YCFdpsRDvEHNcj5rsmvJ5G2XXkW1icJP
- Amount to be sent to the change address: 0.005
- Input addresses, with total-value-to-be-sent:
-- 1BB66Gx4833uKx8Lo2k8Mt4TRk42WTr7cZ: 0.01000000
- Output addresses, with total-value-to-be-received:
-- 12YCFdpsRDvEHNcj5rsmvJ5G2XXkW1icJP: 0.00500000
-- 1H5SUR7Fv7x252WuJPqBjewwpeHuJ218Ky: 0.00500000
- Total value of all inputs: 0.01000000
- Total value of all outputs: 0.01000000
- Total value of all inputs exactly matches total value of all outputs.
- Estimated transaction size: 257 bytes
- Fee rate: 1.0 (satoshi / byte)
- Calculate 257 * 1.0 and round up to nearest satoshi.
- Final fee: 257 (satoshi)
- Final fee rate (using estimated transaction size): 1.0000 (satoshi per byte)
- Fee subtracted from amount-to-be-sent-to-change-address.
- New amount to be sent to change address: 499743 (satoshi)
- Size of signed transaction: 258 bytes
- (signed_tx_size - estimated_tx_size): 1 bytes
- Fee rate in signed transaction: 0.996 (satoshi / byte)

Input 0:
Input: {40 bytes unsigned, 66 bytes signable, 180 bytes signed}
- [data] previous_output_hash: 53d1758c91fb4f3e82b2419282270bf79ae0dd359cb79ba7cab3fd5a7cba649d (32 bytes)
- [data] previous_output_index: 00000000 (4 bytes)
- [signed form] script_length: 8b (1 bytes)
- [signed form] scriptSig: 483045022100f45a55bcab0b3fa6d56494bedf74c2010cd117b7ddc49e07dfe9912402774aef02207a86791e54672005c53828f8afacd2a7ed70fa01a63a384eba1ee5e1e4fc3d130141048b372e0137fbd76f3095098e540f8992febf56c822d023237179e23703d31b6811b21205465d6c0e2cf33c470b1aaa7599200e81a28f546a5afdc0902c03976e (139 bytes)
- [data] sequence: ffffffff (4 bytes)
- [used for signing] private_key_hex: f6c8b60b49c35ef5e6e05e9b06aa5b2b28bd28fbfce696dfc2301347d494a22b (32 bytes)
- [source, goes into scriptSig] public_key_hex: 048b372e0137fbd76f3095098e540f8992febf56c822d023237179e23703d31b6811b21205465d6c0e2cf33c470b1aaa7599200e81a28f546a5afdc0902c03976e (65 bytes)
- [signable form] script_length_scriptPubKey: 19 (1 bytes)
- [signable form] scriptPubKey: 76a9146f99aacb549f7d662e6f82476b572f824387d95488ac (25 bytes)
- [more info] address: 1BB66Gx4833uKx8Lo2k8Mt4TRk42WTr7cZ
- [more info] previous_output_index_int: 0
- [more info] txid: 9d64ba7c5afdb3caa79bb79c35dde09af70b27829241b2823e4ffb918c75d153

Output 0:
Output: {34 bytes}
- [data] value: 1fa0070000000000 (8 bytes)
- [data] script_length: 19 (1 bytes)
- [data] scriptPubKey: 76a91410de69df99d4b834ee6f2bd1466edab556beb7d688ac (25 bytes)
- [more info] address: 12YCFdpsRDvEHNcj5rsmvJ5G2XXkW1icJP
- [more info] bitcoin_amount: 0.00499743
- [more info] satoshi_amount: 499743
- [more info] public_key_hash_hex: 10de69df99d4b834ee6f2bd1466edab556beb7d6

Output 1:
Output: {34 bytes}
- [data] value: 20a1070000000000 (8 bytes)
- [data] script_length: 19 (1 bytes)
- [data] scriptPubKey: 76a914b058f09e25382dd3b9339c25a5727085a22c8c6088ac (25 bytes)
- [more info] address: 1H5SUR7Fv7x252WuJPqBjewwpeHuJ218Ky
- [more info] bitcoin_amount: 0.005
- [more info] satoshi_amount: 500000
- [more info] public_key_hash_hex: b058f09e25382dd3b9339c25a5727085a22c8c60

Transaction (unsigned form): {118 bytes}
- version: 01000000 (4 bytes)
- input_count: 01 (1 bytes)
- Input 0: {40 bytes}
-- previous_output_hash: 53d1758c91fb4f3e82b2419282270bf79ae0dd359cb79ba7cab3fd5a7cba649d (32 bytes)
-- previous_output_index: 00000000 (4 bytes)
-- script_length: [none] (0 bytes)
-- scriptSig: [none] (0 bytes)
-- sequence: ffffffff (4 bytes)
- output_count: 02 (1 bytes)
- Output 0: {34 bytes}
-- value: 1fa0070000000000 (8 bytes)
-- script_length: 19 (1 bytes)
-- scriptPubKey: 76a91410de69df99d4b834ee6f2bd1466edab556beb7d688ac (25 bytes)
- Output 1: {34 bytes}
-- value: 20a1070000000000 (8 bytes)
-- script_length: 19 (1 bytes)
-- scriptPubKey: 76a914b058f09e25382dd3b9339c25a5727085a22c8c6088ac (25 bytes)
- block_lock_time: 00000000 (4 bytes)

Transaction (signable form 0): {148 bytes}
- version: 01000000 (4 bytes)
- input_count: 01 (1 bytes)
- Input 0 [to be used to sign this signable form]: {66 bytes}
-- previous_output_hash: 53d1758c91fb4f3e82b2419282270bf79ae0dd359cb79ba7cab3fd5a7cba649d (32 bytes)
-- previous_output_index: 00000000 (4 bytes)
-- script_length_scriptPubKey: 19 (1 bytes)
-- scriptPubKey: 76a9146f99aacb549f7d662e6f82476b572f824387d95488ac (25 bytes)
-- sequence: ffffffff (4 bytes)
- output_count: 02 (1 bytes)
- Output 0: {34 bytes}
-- value: 1fa0070000000000 (8 bytes)
-- script_length: 19 (1 bytes)
-- scriptPubKey: 76a91410de69df99d4b834ee6f2bd1466edab556beb7d688ac (25 bytes)
- Output 1: {34 bytes}
-- value: 20a1070000000000 (8 bytes)
-- script_length: 19 (1 bytes)
-- scriptPubKey: 76a914b058f09e25382dd3b9339c25a5727085a22c8c6088ac (25 bytes)
- block_lock_time: 00000000 (4 bytes)
- hash_type_4_byte: 01000000 (4 bytes)

Transaction (signed form): {258 bytes}
- version: 01000000 (4 bytes)
- input_count: 01 (1 bytes)
- Input 0: {180 bytes}
-- previous_output_hash: 53d1758c91fb4f3e82b2419282270bf79ae0dd359cb79ba7cab3fd5a7cba649d (32 bytes)
-- previous_output_index: 00000000 (4 bytes)
-- script_length: 8b (1 bytes)
-- scriptSig: 483045022100f45a55bcab0b3fa6d56494bedf74c2010cd117b7ddc49e07dfe9912402774aef02207a86791e54672005c53828f8afacd2a7ed70fa01a63a384eba1ee5e1e4fc3d130141048b372e0137fbd76f3095098e540f8992febf56c822d023237179e23703d31b6811b21205465d6c0e2cf33c470b1aaa7599200e81a28f546a5afdc0902c03976e (139 bytes)
-- sequence: ffffffff (4 bytes)
- output_count: 02 (1 bytes)
- Output 0: {34 bytes}
-- value: 1fa0070000000000 (8 bytes)
-- script_length: 19 (1 bytes)
-- scriptPubKey: 76a91410de69df99d4b834ee6f2bd1466edab556beb7d688ac (25 bytes)
- Output 1: {34 bytes}
-- value: 20a1070000000000 (8 bytes)
-- script_length: 19 (1 bytes)
-- scriptPubKey: 76a914b058f09e25382dd3b9339c25a5727085a22c8c6088ac (25 bytes)
- block_lock_time: 00000000 (4 bytes)

Signed transaction:
010000000153d1758c91fb4f3e82b2419282270bf79ae0dd359cb79ba7cab3fd5a7cba649d000000008b483045022100f45a55bcab0b3fa6d56494bedf74c2010cd117b7ddc49e07dfe9912402774aef02207a86791e54672005c53828f8afacd2a7ed70fa01a63a384eba1ee5e1e4fc3d130141048b372e0137fbd76f3095098e540f8992febf56c822d023237179e23703d31b6811b21205465d6c0e2cf33c470b1aaa7599200e81a28f546a5afdc0902c03976effffffff021fa00700000000001976a91410de69df99d4b834ee6f2bd1466edab556beb7d688ac20a10700000000001976a914b058f09e25382dd3b9339c25a5727085a22c8c6088ac00000000

### END CREATION OF BITCOIN TRANSACTION





Signed transaction T2_v1 (Transaction 2, version 1):

010000000153d1758c91fb4f3e82b2419282270bf79ae0dd359cb79ba7cab3fd5a7cba649d000000008b483045022100f45a55bcab0b3fa6d56494bedf74c2010cd117b7ddc49e07dfe9912402774aef02207a86791e54672005c53828f8afacd2a7ed70fa01a63a384eba1ee5e1e4fc3d130141048b372e0137fbd76f3095098e540f8992febf56c822d023237179e23703d31b6811b21205465d6c0e2cf33c470b1aaa7599200e81a28f546a5afdc0902c03976effffffff021fa00700000000001976a91410de69df99d4b834ee6f2bd1466edab556beb7d688ac20a10700000000001976a914b058f09e25382dd3b9339c25a5727085a22c8c6088ac00000000





Use http://live.blockcypher.com/btc/decodetx to decode T2_v1 and confirm that it's formatted correctly.

Use http://live.blockcypher.com/btc/pushtx to broadcast T2_v1 to the Bitcoin network.

Result: Txid is:
d03971f787c974bdae8b77fef474567cbc6ae2626d85c36872efc9ddea7383f2





Now wait for either
a) T2_v1 to be mined
or
b) T2_v1 to be removed from the memory pools of various visible Bitcoin nodes.


Current datetime:

stjohn@judgement:work$ date

Sun Sep 6 11:48:34 BST 2020



[wait]


stjohn@judgement:~$ date

Mon Sep 7 18:48:49 BST 2020



Have looked up the txid on several block explorers. None of them can find it. This means that the transaction has probably been removed from most major nodes.




Make another version of T2 with a higher fee.

Generate a new random K value with which to sign T2.

K2:
b28780e24336648daa30a9ce4e3585aa8e45942196f76f6d66e57d82db54a11a


Look up current fee rates again. Result: For inclusion in the next 2-8 blocks, the fee rate is 100 satoshi / byte.

In the controls of create_transaction_3.py, set the random_value to be K2 and set the fee rate to be 100.

	##### START CONTROLS
	# Note: Hex characters in input variable values must be lowercase. 
	random_values = [
		"b28780e24336648daa30a9ce4e3585aa8e45942196f76f6d66e57d82db54a11a",
	]
	# random_value must be between 1 and 32 bytes. If random_value_type is "raw_bytes", then random_value must be between 1 and 32 ASCII characters. If random_value_type is "hex_bytes", then random_value must be an even number of hex characters and between 2 and 64 hex characters (1 byte is represented by 2 hex characters). 
	# Note: Every ECDSA signature (one for each input in a transaction) requires new random entropy. 
	# random_value_type options: ["raw_bytes", "hex_bytes"]
	random_value_type = "hex_bytes"
	input_data = [
		{
		"txid": "9d64ba7c5afdb3caa79bb79c35dde09af70b27829241b2823e4ffb918c75d153",
		"previous_output_index": "0",
		"private_key_hex": "f6c8b60b49c35ef5e6e05e9b06aa5b2b28bd28fbfce696dfc2301347d494a22b",
		#"satoshi_amount": "", 
		"bitcoin_amount": "0.01", 
		},
	]
	output_data = [
		{
		"address": "12YCFdpsRDvEHNcj5rsmvJ5G2XXkW1icJP",
		#"satoshi_amount": "", 
		"bitcoin_amount": "0.005", 
		},
		{
		"address": "1H5SUR7Fv7x252WuJPqBjewwpeHuJ218Ky",
		#"satoshi_amount": "", 
		"bitcoin_amount": "0.005", 
		},
	]
	# note: all inputs and outputs are assumed to be Pay-To-Public-Key-Hash (P2PKH). 
	change_address = "12YCFdpsRDvEHNcj5rsmvJ5G2XXkW1icJP"
	# note: the fee will be subtracted from the amount that is being sent to the change address.
	fee = "" # satoshi
	fee_rate = "100" # satoshi / byte
	# fee_type options: ["fee", "fee_rate"]
	fee_type = "fee_rate"
	##### END CONTROLS





stjohn@judgement:work$ python create_transaction_3.py


### START CREATION OF BITCOIN TRANSACTION

- Fee type: fee_rate
- Fee rate: 100.0 (satoshi / byte)
- Number of inputs (i.e. as-yet-unspent outputs): 1
- Number of outputs: 2
- Change address: 12YCFdpsRDvEHNcj5rsmvJ5G2XXkW1icJP
- Amount to be sent to the change address: 0.005
- Input addresses, with total-value-to-be-sent:
-- 1BB66Gx4833uKx8Lo2k8Mt4TRk42WTr7cZ: 0.01000000
- Output addresses, with total-value-to-be-received:
-- 12YCFdpsRDvEHNcj5rsmvJ5G2XXkW1icJP: 0.00500000
-- 1H5SUR7Fv7x252WuJPqBjewwpeHuJ218Ky: 0.00500000
- Total value of all inputs: 0.01000000
- Total value of all outputs: 0.01000000
- Total value of all inputs exactly matches total value of all outputs.
- Estimated transaction size: 257 bytes
- Fee rate: 100.0 (satoshi / byte)
- Calculate 257 * 100.0 and round up to nearest satoshi.
- Final fee: 25700 (satoshi)
- Final fee rate (using estimated transaction size): 100.0000 (satoshi per byte)
- Fee subtracted from amount-to-be-sent-to-change-address.
- New amount to be sent to change address: 474300 (satoshi)
- Size of signed transaction: 258 bytes
- (signed_tx_size - estimated_tx_size): 1 bytes
- Fee rate in signed transaction: 99.612 (satoshi / byte)

Input 0:
Input: {40 bytes unsigned, 66 bytes signable, 180 bytes signed}
- [data] previous_output_hash: 53d1758c91fb4f3e82b2419282270bf79ae0dd359cb79ba7cab3fd5a7cba649d (32 bytes)
- [data] previous_output_index: 00000000 (4 bytes)
- [signed form] script_length: 8b (1 bytes)
- [signed form] scriptSig: 483045022100aac4e36174bafa5dd5f2a0b89d306f8bfa302a42e6590f9a654a514a8ea19b1b022047402e5a9c68605d97f0a42e84c940fab10db0138c32f0c8f4dbb196403f5ea50141048b372e0137fbd76f3095098e540f8992febf56c822d023237179e23703d31b6811b21205465d6c0e2cf33c470b1aaa7599200e81a28f546a5afdc0902c03976e (139 bytes)
- [data] sequence: ffffffff (4 bytes)
- [used for signing] private_key_hex: f6c8b60b49c35ef5e6e05e9b06aa5b2b28bd28fbfce696dfc2301347d494a22b (32 bytes)
- [source, goes into scriptSig] public_key_hex: 048b372e0137fbd76f3095098e540f8992febf56c822d023237179e23703d31b6811b21205465d6c0e2cf33c470b1aaa7599200e81a28f546a5afdc0902c03976e (65 bytes)
- [signable form] script_length_scriptPubKey: 19 (1 bytes)
- [signable form] scriptPubKey: 76a9146f99aacb549f7d662e6f82476b572f824387d95488ac (25 bytes)
- [more info] address: 1BB66Gx4833uKx8Lo2k8Mt4TRk42WTr7cZ
- [more info] previous_output_index_int: 0
- [more info] txid: 9d64ba7c5afdb3caa79bb79c35dde09af70b27829241b2823e4ffb918c75d153

Output 0:
Output: {34 bytes}
- [data] value: bc3c070000000000 (8 bytes)
- [data] script_length: 19 (1 bytes)
- [data] scriptPubKey: 76a91410de69df99d4b834ee6f2bd1466edab556beb7d688ac (25 bytes)
- [more info] address: 12YCFdpsRDvEHNcj5rsmvJ5G2XXkW1icJP
- [more info] bitcoin_amount: 0.00474300
- [more info] satoshi_amount: 474300
- [more info] public_key_hash_hex: 10de69df99d4b834ee6f2bd1466edab556beb7d6

Output 1:
Output: {34 bytes}
- [data] value: 20a1070000000000 (8 bytes)
- [data] script_length: 19 (1 bytes)
- [data] scriptPubKey: 76a914b058f09e25382dd3b9339c25a5727085a22c8c6088ac (25 bytes)
- [more info] address: 1H5SUR7Fv7x252WuJPqBjewwpeHuJ218Ky
- [more info] bitcoin_amount: 0.005
- [more info] satoshi_amount: 500000
- [more info] public_key_hash_hex: b058f09e25382dd3b9339c25a5727085a22c8c60

Transaction (unsigned form): {118 bytes}
- version: 01000000 (4 bytes)
- input_count: 01 (1 bytes)
- Input 0: {40 bytes}
-- previous_output_hash: 53d1758c91fb4f3e82b2419282270bf79ae0dd359cb79ba7cab3fd5a7cba649d (32 bytes)
-- previous_output_index: 00000000 (4 bytes)
-- script_length: [none] (0 bytes)
-- scriptSig: [none] (0 bytes)
-- sequence: ffffffff (4 bytes)
- output_count: 02 (1 bytes)
- Output 0: {34 bytes}
-- value: bc3c070000000000 (8 bytes)
-- script_length: 19 (1 bytes)
-- scriptPubKey: 76a91410de69df99d4b834ee6f2bd1466edab556beb7d688ac (25 bytes)
- Output 1: {34 bytes}
-- value: 20a1070000000000 (8 bytes)
-- script_length: 19 (1 bytes)
-- scriptPubKey: 76a914b058f09e25382dd3b9339c25a5727085a22c8c6088ac (25 bytes)
- block_lock_time: 00000000 (4 bytes)

Transaction (signable form 0): {148 bytes}
- version: 01000000 (4 bytes)
- input_count: 01 (1 bytes)
- Input 0 [to be used to sign this signable form]: {66 bytes}
-- previous_output_hash: 53d1758c91fb4f3e82b2419282270bf79ae0dd359cb79ba7cab3fd5a7cba649d (32 bytes)
-- previous_output_index: 00000000 (4 bytes)
-- script_length_scriptPubKey: 19 (1 bytes)
-- scriptPubKey: 76a9146f99aacb549f7d662e6f82476b572f824387d95488ac (25 bytes)
-- sequence: ffffffff (4 bytes)
- output_count: 02 (1 bytes)
- Output 0: {34 bytes}
-- value: bc3c070000000000 (8 bytes)
-- script_length: 19 (1 bytes)
-- scriptPubKey: 76a91410de69df99d4b834ee6f2bd1466edab556beb7d688ac (25 bytes)
- Output 1: {34 bytes}
-- value: 20a1070000000000 (8 bytes)
-- script_length: 19 (1 bytes)
-- scriptPubKey: 76a914b058f09e25382dd3b9339c25a5727085a22c8c6088ac (25 bytes)
- block_lock_time: 00000000 (4 bytes)
- hash_type_4_byte: 01000000 (4 bytes)

Transaction (signed form): {258 bytes}
- version: 01000000 (4 bytes)
- input_count: 01 (1 bytes)
- Input 0: {180 bytes}
-- previous_output_hash: 53d1758c91fb4f3e82b2419282270bf79ae0dd359cb79ba7cab3fd5a7cba649d (32 bytes)
-- previous_output_index: 00000000 (4 bytes)
-- script_length: 8b (1 bytes)
-- scriptSig: 483045022100aac4e36174bafa5dd5f2a0b89d306f8bfa302a42e6590f9a654a514a8ea19b1b022047402e5a9c68605d97f0a42e84c940fab10db0138c32f0c8f4dbb196403f5ea50141048b372e0137fbd76f3095098e540f8992febf56c822d023237179e23703d31b6811b21205465d6c0e2cf33c470b1aaa7599200e81a28f546a5afdc0902c03976e (139 bytes)
-- sequence: ffffffff (4 bytes)
- output_count: 02 (1 bytes)
- Output 0: {34 bytes}
-- value: bc3c070000000000 (8 bytes)
-- script_length: 19 (1 bytes)
-- scriptPubKey: 76a91410de69df99d4b834ee6f2bd1466edab556beb7d688ac (25 bytes)
- Output 1: {34 bytes}
-- value: 20a1070000000000 (8 bytes)
-- script_length: 19 (1 bytes)
-- scriptPubKey: 76a914b058f09e25382dd3b9339c25a5727085a22c8c6088ac (25 bytes)
- block_lock_time: 00000000 (4 bytes)

Signed transaction:
010000000153d1758c91fb4f3e82b2419282270bf79ae0dd359cb79ba7cab3fd5a7cba649d000000008b483045022100aac4e36174bafa5dd5f2a0b89d306f8bfa302a42e6590f9a654a514a8ea19b1b022047402e5a9c68605d97f0a42e84c940fab10db0138c32f0c8f4dbb196403f5ea50141048b372e0137fbd76f3095098e540f8992febf56c822d023237179e23703d31b6811b21205465d6c0e2cf33c470b1aaa7599200e81a28f546a5afdc0902c03976effffffff02bc3c0700000000001976a91410de69df99d4b834ee6f2bd1466edab556beb7d688ac20a10700000000001976a914b058f09e25382dd3b9339c25a5727085a22c8c6088ac00000000

### END CREATION OF BITCOIN TRANSACTION





Signed transaction T2_v2 (Transaction 2, version 2):

010000000153d1758c91fb4f3e82b2419282270bf79ae0dd359cb79ba7cab3fd5a7cba649d000000008b483045022100aac4e36174bafa5dd5f2a0b89d306f8bfa302a42e6590f9a654a514a8ea19b1b022047402e5a9c68605d97f0a42e84c940fab10db0138c32f0c8f4dbb196403f5ea50141048b372e0137fbd76f3095098e540f8992febf56c822d023237179e23703d31b6811b21205465d6c0e2cf33c470b1aaa7599200e81a28f546a5afdc0902c03976effffffff02bc3c0700000000001976a91410de69df99d4b834ee6f2bd1466edab556beb7d688ac20a10700000000001976a914b058f09e25382dd3b9339c25a5727085a22c8c6088ac00000000





Use http://live.blockcypher.com/btc/decodetx to decode T2_v2 and confirm that it's formatted correctly.

Use http://live.blockcypher.com/btc/pushtx to broadcast T2_v2 to the Bitcoin network.

Result: Txid is:
585f054c01139bdae20ff8fa233c4cda47db6d891a387e37dfd56f9cb39d1bea





Now wait for either
a) T2_v2 to be mined
or
b) T2_v2 to be removed from the memory pools of various visible Bitcoin nodes.


Current datetime:

stjohn@judgement:work$ date

Mon Sep 7 18:59:10 BST 2020



[wait]


stjohn@judgement:work$ date

Mon Sep 7 20:04:11 BST 2020



Transaction T2_v2 now has 6+ confirmations.






Next: Create transaction T3, which will transfer bitcoin from A2 and A3 to addresses A4 and A5.



A2:
12YCFdpsRDvEHNcj5rsmvJ5G2XXkW1icJP


A3:
1H5SUR7Fv7x252WuJPqBjewwpeHuJ218Ky


A4:
136oURWq1zjkdQHKcanE7TyA3o36ibARNM


A5:
12PX5jPyQYejyrU79nZUDmKXvB3ttMfDqZ



Look up the details of the unspent outputs stored in A2 and A3.



stjohn@judgement:work$ python getUTXOsInAddress.py --address 12YCFdpsRDvEHNcj5rsmvJ5G2XXkW1icJP

address: 12YCFdpsRDvEHNcj5rsmvJ5G2XXkW1icJP
- utxo 0:
-- txid: 585f054c01139bdae20ff8fa233c4cda47db6d891a387e37dfd56f9cb39d1bea
-- previous_output_index: 0
-- satoshiValue: 474300
-- bitcoinValue: 0.004743

stjohn@judgement:work$ python getUTXOsInAddress.py --address 1H5SUR7Fv7x252WuJPqBjewwpeHuJ218Ky

- utxo 0:
-- txid: 585f054c01139bdae20ff8fa233c4cda47db6d891a387e37dfd56f9cb39d1bea
-- previous_output_index: 1
-- satoshiValue: 500000
-- bitcoinValue: 0.005



Here are the private keys with which to sign the inputs.

P2:
ecfb8057d4e053dda6849f6a361ca2d6797368651bbb2b52ce4691515a7909e1


P3:
fc8c7e92b44fe66f8f20d98a648f659da69461661673e22292a67dc20742ef17



Generate new random K values with which to sign T3.

K3:
0a5a9cc087cf3337bfb0fa12f6fa036d17d6b6dc0e93dfa657c8caca47ad8155


K4:
2493ac84058e4f4b79f1bd267c45f52bc7545ef01dd66b8bf077cae86460e954



Look up current fee rates again. Result: A fee rate of 100 satoshi / byte is estimated to get the transaction mined in the next 3-8 blocks.

In the controls of create_transaction_3.py, set the random_values to be K3 and K4 and set the fee rate to be 100.

Set A4 as the change address. The fee will then be subtracted from its output value.

	##### START CONTROLS
	# Note: Hex characters in input variable values must be lowercase. 
	random_values = [
		"0a5a9cc087cf3337bfb0fa12f6fa036d17d6b6dc0e93dfa657c8caca47ad8155",
		"2493ac84058e4f4b79f1bd267c45f52bc7545ef01dd66b8bf077cae86460e954",
	]
	# random_value must be between 1 and 32 bytes. If random_value_type is "raw_bytes", then random_value must be between 1 and 32 ASCII characters. If random_value_type is "hex_bytes", then random_value must be an even number of hex characters and between 2 and 64 hex characters (1 byte is represented by 2 hex characters). 
	# Note: Every ECDSA signature (one for each input in a transaction) requires new random entropy. 
	# random_value_type options: ["raw_bytes", "hex_bytes"]
	random_value_type = "hex_bytes"
	input_data = [
		{
		"txid": "585f054c01139bdae20ff8fa233c4cda47db6d891a387e37dfd56f9cb39d1bea",
		"previous_output_index": "0",
		"private_key_hex": "ecfb8057d4e053dda6849f6a361ca2d6797368651bbb2b52ce4691515a7909e1",
		#"satoshi_amount": "", 
		"bitcoin_amount": "0.004743", 
		},
		{
		"txid": "585f054c01139bdae20ff8fa233c4cda47db6d891a387e37dfd56f9cb39d1bea",
		"previous_output_index": "1",
		"private_key_hex": "fc8c7e92b44fe66f8f20d98a648f659da69461661673e22292a67dc20742ef17",
		#"satoshi_amount": "", 
		"bitcoin_amount": "0.005", 
		},
	]
	output_data = [
		{
		"address": "136oURWq1zjkdQHKcanE7TyA3o36ibARNM",
		#"satoshi_amount": "", 
		"bitcoin_amount": "0.004743", 
		},
		{
		"address": "12PX5jPyQYejyrU79nZUDmKXvB3ttMfDqZ",
		#"satoshi_amount": "", 
		"bitcoin_amount": "0.005", 
		},
	]
	# note: all inputs and outputs are assumed to be Pay-To-Public-Key-Hash (P2PKH). 
	change_address = "136oURWq1zjkdQHKcanE7TyA3o36ibARNM"
	# note: the fee will be subtracted from the amount that is being sent to the change address.
	fee = "" # satoshi
	fee_rate = "100" # satoshi / byte
	# fee_type options: ["fee", "fee_rate"]
	fee_type = "fee_rate"
	##### END CONTROLS





Create and sign the transaction.


stjohn@judgement:work$ python create_transaction_3.py


### START CREATION OF BITCOIN TRANSACTION

- Fee type: fee_rate
- Fee rate: 100.0 (satoshi / byte)
- Number of inputs (i.e. as-yet-unspent outputs): 2
- Number of outputs: 2
- Change address: 136oURWq1zjkdQHKcanE7TyA3o36ibARNM
- Amount to be sent to the change address: 0.004743
- Input addresses, with total-value-to-be-sent:
-- 12YCFdpsRDvEHNcj5rsmvJ5G2XXkW1icJP: 0.00474300
-- 1H5SUR7Fv7x252WuJPqBjewwpeHuJ218Ky: 0.00500000
- Output addresses, with total-value-to-be-received:
-- 12PX5jPyQYejyrU79nZUDmKXvB3ttMfDqZ: 0.00500000
-- 136oURWq1zjkdQHKcanE7TyA3o36ibARNM: 0.00474300
- Total value of all inputs: 0.00974300
- Total value of all outputs: 0.00974300
- Total value of all inputs exactly matches total value of all outputs.
- Estimated transaction size: 436 bytes
- Fee rate: 100.0 (satoshi / byte)
- Calculate 436 * 100.0 and round up to nearest satoshi.
- Final fee: 43600 (satoshi)
- Final fee rate (using estimated transaction size): 100.0000 (satoshi per byte)
- Fee subtracted from amount-to-be-sent-to-change-address.
- New amount to be sent to change address: 430700 (satoshi)
- Size of signed transaction: 438 bytes
- (signed_tx_size - estimated_tx_size): 2 bytes
- Fee rate in signed transaction: 99.543 (satoshi / byte)

Input 0:
Input: {40 bytes unsigned, 66 bytes signable, 180 bytes signed}
- [data] previous_output_hash: ea1b9db39c6fd5df377e381a896ddb47da4c3c23faf80fe2da9b13014c055f58 (32 bytes)
- [data] previous_output_index: 00000000 (4 bytes)
- [signed form] script_length: 8b (1 bytes)
- [signed form] scriptSig: 483045022100d75efc99b640bcc09f569b1b53cb33d407720f9931a719d0ae3212182927cbb802205ea59d7e86f3bdcf7ec5b483a181704909e401cdeb3f8c60172d72aa842ec142014104e5f0aa4e9ee32cc982db529c981f18171cd9d1ccf224a94e4b3c09b51fd3752c6ebf66f0861dc435fee962f995ab9c5346d32332a409c598eb575cec74115180 (139 bytes)
- [data] sequence: ffffffff (4 bytes)
- [used for signing] private_key_hex: ecfb8057d4e053dda6849f6a361ca2d6797368651bbb2b52ce4691515a7909e1 (32 bytes)
- [source, goes into scriptSig] public_key_hex: 04e5f0aa4e9ee32cc982db529c981f18171cd9d1ccf224a94e4b3c09b51fd3752c6ebf66f0861dc435fee962f995ab9c5346d32332a409c598eb575cec74115180 (65 bytes)
- [signable form] script_length_scriptPubKey: 19 (1 bytes)
- [signable form] scriptPubKey: 76a91410de69df99d4b834ee6f2bd1466edab556beb7d688ac (25 bytes)
- [more info] address: 12YCFdpsRDvEHNcj5rsmvJ5G2XXkW1icJP
- [more info] previous_output_index_int: 0
- [more info] txid: 585f054c01139bdae20ff8fa233c4cda47db6d891a387e37dfd56f9cb39d1bea

Input 1:
Input: {40 bytes unsigned, 66 bytes signable, 180 bytes signed}
- [data] previous_output_hash: ea1b9db39c6fd5df377e381a896ddb47da4c3c23faf80fe2da9b13014c055f58 (32 bytes)
- [data] previous_output_index: 01000000 (4 bytes)
- [signed form] script_length: 8b (1 bytes)
- [signed form] scriptSig: 483045022100c70dbea33b9a7d51a9f952a63d65f0572194af68774c09e03d347f65cddd38c3022072e8341e85f5cb6c49be050c862837d451f46a6f5d0f51fa80993a45983cf9d6014104cca91b1ad65fc428789b469f0e030fb2de58132c61f3240f416e3a6eb1963009a359770805e71e9b7c7982da51c2a3209ec908efe71cf5ec8b65f5b9eb05115b (139 bytes)
- [data] sequence: ffffffff (4 bytes)
- [used for signing] private_key_hex: fc8c7e92b44fe66f8f20d98a648f659da69461661673e22292a67dc20742ef17 (32 bytes)
- [source, goes into scriptSig] public_key_hex: 04cca91b1ad65fc428789b469f0e030fb2de58132c61f3240f416e3a6eb1963009a359770805e71e9b7c7982da51c2a3209ec908efe71cf5ec8b65f5b9eb05115b (65 bytes)
- [signable form] script_length_scriptPubKey: 19 (1 bytes)
- [signable form] scriptPubKey: 76a914b058f09e25382dd3b9339c25a5727085a22c8c6088ac (25 bytes)
- [more info] address: 1H5SUR7Fv7x252WuJPqBjewwpeHuJ218Ky
- [more info] previous_output_index_int: 1
- [more info] txid: 585f054c01139bdae20ff8fa233c4cda47db6d891a387e37dfd56f9cb39d1bea

Output 0:
Output: {34 bytes}
- [data] value: 6c92060000000000 (8 bytes)
- [data] script_length: 19 (1 bytes)
- [data] scriptPubKey: 76a91417091ffac2b6bb51d9fd1d979fac6ec6bf3a2f1e88ac (25 bytes)
- [more info] address: 136oURWq1zjkdQHKcanE7TyA3o36ibARNM
- [more info] bitcoin_amount: 0.00430700
- [more info] satoshi_amount: 430700
- [more info] public_key_hash_hex: 17091ffac2b6bb51d9fd1d979fac6ec6bf3a2f1e

Output 1:
Output: {34 bytes}
- [data] value: 20a1070000000000 (8 bytes)
- [data] script_length: 19 (1 bytes)
- [data] scriptPubKey: 76a9140f3a634504545b37a97b10214b2f640fb16085e588ac (25 bytes)
- [more info] address: 12PX5jPyQYejyrU79nZUDmKXvB3ttMfDqZ
- [more info] bitcoin_amount: 0.005
- [more info] satoshi_amount: 500000
- [more info] public_key_hash_hex: 0f3a634504545b37a97b10214b2f640fb16085e5

Transaction (unsigned form): {158 bytes}
- version: 01000000 (4 bytes)
- input_count: 02 (1 bytes)
- Input 0: {40 bytes}
-- previous_output_hash: ea1b9db39c6fd5df377e381a896ddb47da4c3c23faf80fe2da9b13014c055f58 (32 bytes)
-- previous_output_index: 00000000 (4 bytes)
-- script_length: [none] (0 bytes)
-- scriptSig: [none] (0 bytes)
-- sequence: ffffffff (4 bytes)
- Input 1: {40 bytes}
-- previous_output_hash: ea1b9db39c6fd5df377e381a896ddb47da4c3c23faf80fe2da9b13014c055f58 (32 bytes)
-- previous_output_index: 01000000 (4 bytes)
-- script_length: [none] (0 bytes)
-- scriptSig: [none] (0 bytes)
-- sequence: ffffffff (4 bytes)
- output_count: 02 (1 bytes)
- Output 0: {34 bytes}
-- value: 6c92060000000000 (8 bytes)
-- script_length: 19 (1 bytes)
-- scriptPubKey: 76a91417091ffac2b6bb51d9fd1d979fac6ec6bf3a2f1e88ac (25 bytes)
- Output 1: {34 bytes}
-- value: 20a1070000000000 (8 bytes)
-- script_length: 19 (1 bytes)
-- scriptPubKey: 76a9140f3a634504545b37a97b10214b2f640fb16085e588ac (25 bytes)
- block_lock_time: 00000000 (4 bytes)

Transaction (signable form 0): {189 bytes}
- version: 01000000 (4 bytes)
- input_count: 02 (1 bytes)
- Input 0 [to be used to sign this signable form]: {66 bytes}
-- previous_output_hash: ea1b9db39c6fd5df377e381a896ddb47da4c3c23faf80fe2da9b13014c055f58 (32 bytes)
-- previous_output_index: 00000000 (4 bytes)
-- script_length_scriptPubKey: 19 (1 bytes)
-- scriptPubKey: 76a91410de69df99d4b834ee6f2bd1466edab556beb7d688ac (25 bytes)
-- sequence: ffffffff (4 bytes)
- Input 1: {41 bytes}
-- previous_output_hash: ea1b9db39c6fd5df377e381a896ddb47da4c3c23faf80fe2da9b13014c055f58 (32 bytes)
-- previous_output_index: 01000000 (4 bytes)
-- script_length: 00 (1 bytes)
-- sequence: ffffffff (4 bytes)
- output_count: 02 (1 bytes)
- Output 0: {34 bytes}
-- value: 6c92060000000000 (8 bytes)
-- script_length: 19 (1 bytes)
-- scriptPubKey: 76a91417091ffac2b6bb51d9fd1d979fac6ec6bf3a2f1e88ac (25 bytes)
- Output 1: {34 bytes}
-- value: 20a1070000000000 (8 bytes)
-- script_length: 19 (1 bytes)
-- scriptPubKey: 76a9140f3a634504545b37a97b10214b2f640fb16085e588ac (25 bytes)
- block_lock_time: 00000000 (4 bytes)
- hash_type_4_byte: 01000000 (4 bytes)

Transaction (signable form 1): {189 bytes}
- version: 01000000 (4 bytes)
- input_count: 02 (1 bytes)
- Input 0: {41 bytes}
-- previous_output_hash: ea1b9db39c6fd5df377e381a896ddb47da4c3c23faf80fe2da9b13014c055f58 (32 bytes)
-- previous_output_index: 00000000 (4 bytes)
-- script_length: 00 (1 bytes)
-- sequence: ffffffff (4 bytes)
- Input 1 [to be used to sign this signable form]: {66 bytes}
-- previous_output_hash: ea1b9db39c6fd5df377e381a896ddb47da4c3c23faf80fe2da9b13014c055f58 (32 bytes)
-- previous_output_index: 01000000 (4 bytes)
-- script_length_scriptPubKey: 19 (1 bytes)
-- scriptPubKey: 76a914b058f09e25382dd3b9339c25a5727085a22c8c6088ac (25 bytes)
-- sequence: ffffffff (4 bytes)
- output_count: 02 (1 bytes)
- Output 0: {34 bytes}
-- value: 6c92060000000000 (8 bytes)
-- script_length: 19 (1 bytes)
-- scriptPubKey: 76a91417091ffac2b6bb51d9fd1d979fac6ec6bf3a2f1e88ac (25 bytes)
- Output 1: {34 bytes}
-- value: 20a1070000000000 (8 bytes)
-- script_length: 19 (1 bytes)
-- scriptPubKey: 76a9140f3a634504545b37a97b10214b2f640fb16085e588ac (25 bytes)
- block_lock_time: 00000000 (4 bytes)
- hash_type_4_byte: 01000000 (4 bytes)

Transaction (signed form): {438 bytes}
- version: 01000000 (4 bytes)
- input_count: 02 (1 bytes)
- Input 0: {180 bytes}
-- previous_output_hash: ea1b9db39c6fd5df377e381a896ddb47da4c3c23faf80fe2da9b13014c055f58 (32 bytes)
-- previous_output_index: 00000000 (4 bytes)
-- script_length: 8b (1 bytes)
-- scriptSig: 483045022100d75efc99b640bcc09f569b1b53cb33d407720f9931a719d0ae3212182927cbb802205ea59d7e86f3bdcf7ec5b483a181704909e401cdeb3f8c60172d72aa842ec142014104e5f0aa4e9ee32cc982db529c981f18171cd9d1ccf224a94e4b3c09b51fd3752c6ebf66f0861dc435fee962f995ab9c5346d32332a409c598eb575cec74115180 (139 bytes)
-- sequence: ffffffff (4 bytes)
- Input 1: {180 bytes}
-- previous_output_hash: ea1b9db39c6fd5df377e381a896ddb47da4c3c23faf80fe2da9b13014c055f58 (32 bytes)
-- previous_output_index: 01000000 (4 bytes)
-- script_length: 8b (1 bytes)
-- scriptSig: 483045022100c70dbea33b9a7d51a9f952a63d65f0572194af68774c09e03d347f65cddd38c3022072e8341e85f5cb6c49be050c862837d451f46a6f5d0f51fa80993a45983cf9d6014104cca91b1ad65fc428789b469f0e030fb2de58132c61f3240f416e3a6eb1963009a359770805e71e9b7c7982da51c2a3209ec908efe71cf5ec8b65f5b9eb05115b (139 bytes)
-- sequence: ffffffff (4 bytes)
- output_count: 02 (1 bytes)
- Output 0: {34 bytes}
-- value: 6c92060000000000 (8 bytes)
-- script_length: 19 (1 bytes)
-- scriptPubKey: 76a91417091ffac2b6bb51d9fd1d979fac6ec6bf3a2f1e88ac (25 bytes)
- Output 1: {34 bytes}
-- value: 20a1070000000000 (8 bytes)
-- script_length: 19 (1 bytes)
-- scriptPubKey: 76a9140f3a634504545b37a97b10214b2f640fb16085e588ac (25 bytes)
- block_lock_time: 00000000 (4 bytes)

Signed transaction:
0100000002ea1b9db39c6fd5df377e381a896ddb47da4c3c23faf80fe2da9b13014c055f58000000008b483045022100d75efc99b640bcc09f569b1b53cb33d407720f9931a719d0ae3212182927cbb802205ea59d7e86f3bdcf7ec5b483a181704909e401cdeb3f8c60172d72aa842ec142014104e5f0aa4e9ee32cc982db529c981f18171cd9d1ccf224a94e4b3c09b51fd3752c6ebf66f0861dc435fee962f995ab9c5346d32332a409c598eb575cec74115180ffffffffea1b9db39c6fd5df377e381a896ddb47da4c3c23faf80fe2da9b13014c055f58010000008b483045022100c70dbea33b9a7d51a9f952a63d65f0572194af68774c09e03d347f65cddd38c3022072e8341e85f5cb6c49be050c862837d451f46a6f5d0f51fa80993a45983cf9d6014104cca91b1ad65fc428789b469f0e030fb2de58132c61f3240f416e3a6eb1963009a359770805e71e9b7c7982da51c2a3209ec908efe71cf5ec8b65f5b9eb05115bffffffff026c920600000000001976a91417091ffac2b6bb51d9fd1d979fac6ec6bf3a2f1e88ac20a10700000000001976a9140f3a634504545b37a97b10214b2f640fb16085e588ac00000000

### END CREATION OF BITCOIN TRANSACTION





Signed transaction T3:

0100000002ea1b9db39c6fd5df377e381a896ddb47da4c3c23faf80fe2da9b13014c055f58000000008b483045022100d75efc99b640bcc09f569b1b53cb33d407720f9931a719d0ae3212182927cbb802205ea59d7e86f3bdcf7ec5b483a181704909e401cdeb3f8c60172d72aa842ec142014104e5f0aa4e9ee32cc982db529c981f18171cd9d1ccf224a94e4b3c09b51fd3752c6ebf66f0861dc435fee962f995ab9c5346d32332a409c598eb575cec74115180ffffffffea1b9db39c6fd5df377e381a896ddb47da4c3c23faf80fe2da9b13014c055f58010000008b483045022100c70dbea33b9a7d51a9f952a63d65f0572194af68774c09e03d347f65cddd38c3022072e8341e85f5cb6c49be050c862837d451f46a6f5d0f51fa80993a45983cf9d6014104cca91b1ad65fc428789b469f0e030fb2de58132c61f3240f416e3a6eb1963009a359770805e71e9b7c7982da51c2a3209ec908efe71cf5ec8b65f5b9eb05115bffffffff026c920600000000001976a91417091ffac2b6bb51d9fd1d979fac6ec6bf3a2f1e88ac20a10700000000001976a9140f3a634504545b37a97b10214b2f640fb16085e588ac00000000





Use http://live.blockcypher.com/btc/decodetx to decode T3 and confirm that it's formatted correctly.

Use http://live.blockcypher.com/btc/pushtx to broadcast T3 to the Bitcoin network.

Result: Txid is:
2b0cef7b0abfefeb6c7c6b228930e6218e86e9d8c33f5525d10f34f91cc7bad4





Now wait for either
a) T3 to be mined
or
b) T3 to be removed from the memory pools of various visible Bitcoin nodes.


Current datetime:

stjohn@judgement:work$ date

Thu Sep 10 20:30:58 BST 2020




[wait]



stjohn@judgement:work$ date

Thu Sep 10 21:39:25 BST 2020




T3 now has 6+ confirmations.








Next: Create transaction T4, which will transfer bitcoin from A4 and A5 to address A6.




A4:
136oURWq1zjkdQHKcanE7TyA3o36ibARNM


A5:
12PX5jPyQYejyrU79nZUDmKXvB3ttMfDqZ


A6:
1LVenxwqnmvwjjBdyUByWsD7mXNmJJP2ZF




Look up the details of the unspent outputs stored in A4 and A5.

stjohn@judgement:work$ python getUTXOsInAddress.py --address 136oURWq1zjkdQHKcanE7TyA3o36ibARNM

address: 136oURWq1zjkdQHKcanE7TyA3o36ibARNM
- utxo 0:
-- txid: 2b0cef7b0abfefeb6c7c6b228930e6218e86e9d8c33f5525d10f34f91cc7bad4
-- previous_output_index: 0
-- satoshiValue: 430700
-- bitcoinValue: 0.004307

stjohn@judgement:work$ python getUTXOsInAddress.py --address 12PX5jPyQYejyrU79nZUDmKXvB3ttMfDqZ

address: 12PX5jPyQYejyrU79nZUDmKXvB3ttMfDqZ
- utxo 0:
-- txid: 2b0cef7b0abfefeb6c7c6b228930e6218e86e9d8c33f5525d10f34f91cc7bad4
-- previous_output_index: 1
-- satoshiValue: 500000
-- bitcoinValue: 0.005




Here are the private keys with which to sign the inputs.

P4:
f7def6819cf8efb7c4aeaddecb951688bcda37cee73b92f73a29be076e66579c


P5:
11717a85a51ba5cd1711905816a694bdd288d0639f27d8bb113ba94df9da1501




Generate new random K values with which to sign T4.

K5:
2423bd4f4af0c89f5cd4a9116905da27d2b5a6abc2c5e5151106035b02e90076


K6:
d79be13627e92605f26ce76e6a6e3cf7943d9a2d161760662fcef47583dc8731




Look up current fee rates again. Result: A fee rate of 100 satoshi / byte is estimated to get the transaction mined in the next 3-7 blocks.



In the controls of create_transaction_3.py, set the random_values to be K5 and K6 and set the fee rate to be 100.

Set A6 as the change address. The fee will be subtracted from the single output value.

	# Note: Hex characters in input variable values must be lowercase. 
	random_values = [
		"2423bd4f4af0c89f5cd4a9116905da27d2b5a6abc2c5e5151106035b02e90076",
		"d79be13627e92605f26ce76e6a6e3cf7943d9a2d161760662fcef47583dc8731",
	]
	# random_value must be between 1 and 32 bytes. If random_value_type is "raw_bytes", then random_value must be between 1 and 32 ASCII characters. If random_value_type is "hex_bytes", then random_value must be an even number of hex characters and between 2 and 64 hex characters (1 byte is represented by 2 hex characters). 
	# Note: Every ECDSA signature (one for each input in a transaction) requires new random entropy. 
	# random_value_type options: ["raw_bytes", "hex_bytes"]
	random_value_type = "hex_bytes"
	input_data = [
		{
		"txid": "2b0cef7b0abfefeb6c7c6b228930e6218e86e9d8c33f5525d10f34f91cc7bad4",
		"previous_output_index": "0",
		"private_key_hex": "f7def6819cf8efb7c4aeaddecb951688bcda37cee73b92f73a29be076e66579c",
		#"satoshi_amount": "", 
		"bitcoin_amount": "0.004307", 
		},
		{
		"txid": "2b0cef7b0abfefeb6c7c6b228930e6218e86e9d8c33f5525d10f34f91cc7bad4",
		"previous_output_index": "1",
		"private_key_hex": "11717a85a51ba5cd1711905816a694bdd288d0639f27d8bb113ba94df9da1501",
		#"satoshi_amount": "", 
		"bitcoin_amount": "0.005", 
		},
	]
	output_data = [
		{
		"address": "1LVenxwqnmvwjjBdyUByWsD7mXNmJJP2ZF",
		#"satoshi_amount": "", 
		"bitcoin_amount": "0.009307", 
		},
	]
	# note: all inputs and outputs are assumed to be Pay-To-Public-Key-Hash (P2PKH). 
	change_address = "1LVenxwqnmvwjjBdyUByWsD7mXNmJJP2ZF"
	# note: the fee will be subtracted from the amount that is being sent to the change address.
	fee = "" # satoshi
	fee_rate = "100" # satoshi / byte
	# fee_type options: ["fee", "fee_rate"]
	fee_type = "fee_rate"
	##### END CONTROLS





Create and sign the transaction.


stjohn@judgement:work$ python create_transaction_3.py


### START CREATION OF BITCOIN TRANSACTION

- Fee type: fee_rate
- Fee rate: 100.0 (satoshi / byte)
- Number of inputs (i.e. as-yet-unspent outputs): 2
- Number of outputs: 1
- Change address: 1LVenxwqnmvwjjBdyUByWsD7mXNmJJP2ZF
- Amount to be sent to the change address: 0.009307
- Input addresses, with total-value-to-be-sent:
-- 12PX5jPyQYejyrU79nZUDmKXvB3ttMfDqZ: 0.00500000
-- 136oURWq1zjkdQHKcanE7TyA3o36ibARNM: 0.00430700
- Output addresses, with total-value-to-be-received:
-- 1LVenxwqnmvwjjBdyUByWsD7mXNmJJP2ZF: 0.00930700
- Total value of all inputs: 0.00930700
- Total value of all outputs: 0.00930700
- Total value of all inputs exactly matches total value of all outputs.
- Estimated transaction size: 402 bytes
- Fee rate: 100.0 (satoshi / byte)
- Calculate 402 * 100.0 and round up to nearest satoshi.
- Final fee: 40200 (satoshi)
- Final fee rate (using estimated transaction size): 100.0000 (satoshi per byte)
- Fee subtracted from amount-to-be-sent-to-change-address.
- New amount to be sent to change address: 890500 (satoshi)
- Size of signed transaction: 402 bytes
- (signed_tx_size - estimated_tx_size): 0 bytes
- Fee rate in signed transaction: 100.0 (satoshi / byte)

Input 0:
Input: {40 bytes unsigned, 66 bytes signable, 179 bytes signed}
- [data] previous_output_hash: d4bac71cf9340fd125553fc3d8e9868e21e63089226b7c6cebefbf0a7bef0c2b (32 bytes)
- [data] previous_output_index: 00000000 (4 bytes)
- [signed form] script_length: 8a (1 bytes)
- [signed form] scriptSig: 47304402202c76a68f7eae79f50034a0a7b3b3dca729f03be1f17c445ad3762ec286a6055402202f8eabbb81a3adc8a6b70ca95dc7972489c6ed28e80be1d8775d00eaf37846640141042d09248cf80095d875561c83adc572f7bae3ff39832f9028b7abd792b4e439b2d522e9b461e8bbaf937c6165a1767b9a105268f013e424e6f7101b042d1dc5ed (138 bytes)
- [data] sequence: ffffffff (4 bytes)
- [used for signing] private_key_hex: f7def6819cf8efb7c4aeaddecb951688bcda37cee73b92f73a29be076e66579c (32 bytes)
- [source, goes into scriptSig] public_key_hex: 042d09248cf80095d875561c83adc572f7bae3ff39832f9028b7abd792b4e439b2d522e9b461e8bbaf937c6165a1767b9a105268f013e424e6f7101b042d1dc5ed (65 bytes)
- [signable form] script_length_scriptPubKey: 19 (1 bytes)
- [signable form] scriptPubKey: 76a91417091ffac2b6bb51d9fd1d979fac6ec6bf3a2f1e88ac (25 bytes)
- [more info] address: 136oURWq1zjkdQHKcanE7TyA3o36ibARNM
- [more info] previous_output_index_int: 0
- [more info] txid: 2b0cef7b0abfefeb6c7c6b228930e6218e86e9d8c33f5525d10f34f91cc7bad4

Input 1:
Input: {40 bytes unsigned, 66 bytes signable, 179 bytes signed}
- [data] previous_output_hash: d4bac71cf9340fd125553fc3d8e9868e21e63089226b7c6cebefbf0a7bef0c2b (32 bytes)
- [data] previous_output_index: 01000000 (4 bytes)
- [signed form] script_length: 8a (1 bytes)
- [signed form] scriptSig: 47304402205a092cff6c5776e555c4cdbfb8a2dcf696e34fab1202e6d542827b8721c75f56022032b83b3b93f384aaef84b3c0894b5f05917b886ef46f2df61fb5e0c91e62139c0141041489ca134cf898df4e58182cec872126b7a2e635c2db547bda3c27b2b1ea65d145b4563745bac943c8df62be7651a2ec700653c7ebf77d15f8aae48a6e33929f (138 bytes)
- [data] sequence: ffffffff (4 bytes)
- [used for signing] private_key_hex: 11717a85a51ba5cd1711905816a694bdd288d0639f27d8bb113ba94df9da1501 (32 bytes)
- [source, goes into scriptSig] public_key_hex: 041489ca134cf898df4e58182cec872126b7a2e635c2db547bda3c27b2b1ea65d145b4563745bac943c8df62be7651a2ec700653c7ebf77d15f8aae48a6e33929f (65 bytes)
- [signable form] script_length_scriptPubKey: 19 (1 bytes)
- [signable form] scriptPubKey: 76a9140f3a634504545b37a97b10214b2f640fb16085e588ac (25 bytes)
- [more info] address: 12PX5jPyQYejyrU79nZUDmKXvB3ttMfDqZ
- [more info] previous_output_index_int: 1
- [more info] txid: 2b0cef7b0abfefeb6c7c6b228930e6218e86e9d8c33f5525d10f34f91cc7bad4

Output 0:
Output: {34 bytes}
- [data] value: 84960d0000000000 (8 bytes)
- [data] script_length: 19 (1 bytes)
- [data] scriptPubKey: 76a914d5d5959ba3035c57b81e9178a8a34e6e7d9580c888ac (25 bytes)
- [more info] address: 1LVenxwqnmvwjjBdyUByWsD7mXNmJJP2ZF
- [more info] bitcoin_amount: 0.00890500
- [more info] satoshi_amount: 890500
- [more info] public_key_hash_hex: d5d5959ba3035c57b81e9178a8a34e6e7d9580c8

Transaction (unsigned form): {124 bytes}
- version: 01000000 (4 bytes)
- input_count: 02 (1 bytes)
- Input 0: {40 bytes}
-- previous_output_hash: d4bac71cf9340fd125553fc3d8e9868e21e63089226b7c6cebefbf0a7bef0c2b (32 bytes)
-- previous_output_index: 00000000 (4 bytes)
-- script_length: [none] (0 bytes)
-- scriptSig: [none] (0 bytes)
-- sequence: ffffffff (4 bytes)
- Input 1: {40 bytes}
-- previous_output_hash: d4bac71cf9340fd125553fc3d8e9868e21e63089226b7c6cebefbf0a7bef0c2b (32 bytes)
-- previous_output_index: 01000000 (4 bytes)
-- script_length: [none] (0 bytes)
-- scriptSig: [none] (0 bytes)
-- sequence: ffffffff (4 bytes)
- output_count: 01 (1 bytes)
- Output 0: {34 bytes}
-- value: 84960d0000000000 (8 bytes)
-- script_length: 19 (1 bytes)
-- scriptPubKey: 76a914d5d5959ba3035c57b81e9178a8a34e6e7d9580c888ac (25 bytes)
- block_lock_time: 00000000 (4 bytes)

Transaction (signable form 0): {155 bytes}
- version: 01000000 (4 bytes)
- input_count: 02 (1 bytes)
- Input 0 [to be used to sign this signable form]: {66 bytes}
-- previous_output_hash: d4bac71cf9340fd125553fc3d8e9868e21e63089226b7c6cebefbf0a7bef0c2b (32 bytes)
-- previous_output_index: 00000000 (4 bytes)
-- script_length_scriptPubKey: 19 (1 bytes)
-- scriptPubKey: 76a91417091ffac2b6bb51d9fd1d979fac6ec6bf3a2f1e88ac (25 bytes)
-- sequence: ffffffff (4 bytes)
- Input 1: {41 bytes}
-- previous_output_hash: d4bac71cf9340fd125553fc3d8e9868e21e63089226b7c6cebefbf0a7bef0c2b (32 bytes)
-- previous_output_index: 01000000 (4 bytes)
-- script_length: 00 (1 bytes)
-- sequence: ffffffff (4 bytes)
- output_count: 01 (1 bytes)
- Output 0: {34 bytes}
-- value: 84960d0000000000 (8 bytes)
-- script_length: 19 (1 bytes)
-- scriptPubKey: 76a914d5d5959ba3035c57b81e9178a8a34e6e7d9580c888ac (25 bytes)
- block_lock_time: 00000000 (4 bytes)
- hash_type_4_byte: 01000000 (4 bytes)

Transaction (signable form 1): {155 bytes}
- version: 01000000 (4 bytes)
- input_count: 02 (1 bytes)
- Input 0: {41 bytes}
-- previous_output_hash: d4bac71cf9340fd125553fc3d8e9868e21e63089226b7c6cebefbf0a7bef0c2b (32 bytes)
-- previous_output_index: 00000000 (4 bytes)
-- script_length: 00 (1 bytes)
-- sequence: ffffffff (4 bytes)
- Input 1 [to be used to sign this signable form]: {66 bytes}
-- previous_output_hash: d4bac71cf9340fd125553fc3d8e9868e21e63089226b7c6cebefbf0a7bef0c2b (32 bytes)
-- previous_output_index: 01000000 (4 bytes)
-- script_length_scriptPubKey: 19 (1 bytes)
-- scriptPubKey: 76a9140f3a634504545b37a97b10214b2f640fb16085e588ac (25 bytes)
-- sequence: ffffffff (4 bytes)
- output_count: 01 (1 bytes)
- Output 0: {34 bytes}
-- value: 84960d0000000000 (8 bytes)
-- script_length: 19 (1 bytes)
-- scriptPubKey: 76a914d5d5959ba3035c57b81e9178a8a34e6e7d9580c888ac (25 bytes)
- block_lock_time: 00000000 (4 bytes)
- hash_type_4_byte: 01000000 (4 bytes)

Transaction (signed form): {402 bytes}
- version: 01000000 (4 bytes)
- input_count: 02 (1 bytes)
- Input 0: {179 bytes}
-- previous_output_hash: d4bac71cf9340fd125553fc3d8e9868e21e63089226b7c6cebefbf0a7bef0c2b (32 bytes)
-- previous_output_index: 00000000 (4 bytes)
-- script_length: 8a (1 bytes)
-- scriptSig: 47304402202c76a68f7eae79f50034a0a7b3b3dca729f03be1f17c445ad3762ec286a6055402202f8eabbb81a3adc8a6b70ca95dc7972489c6ed28e80be1d8775d00eaf37846640141042d09248cf80095d875561c83adc572f7bae3ff39832f9028b7abd792b4e439b2d522e9b461e8bbaf937c6165a1767b9a105268f013e424e6f7101b042d1dc5ed (138 bytes)
-- sequence: ffffffff (4 bytes)
- Input 1: {179 bytes}
-- previous_output_hash: d4bac71cf9340fd125553fc3d8e9868e21e63089226b7c6cebefbf0a7bef0c2b (32 bytes)
-- previous_output_index: 01000000 (4 bytes)
-- script_length: 8a (1 bytes)
-- scriptSig: 47304402205a092cff6c5776e555c4cdbfb8a2dcf696e34fab1202e6d542827b8721c75f56022032b83b3b93f384aaef84b3c0894b5f05917b886ef46f2df61fb5e0c91e62139c0141041489ca134cf898df4e58182cec872126b7a2e635c2db547bda3c27b2b1ea65d145b4563745bac943c8df62be7651a2ec700653c7ebf77d15f8aae48a6e33929f (138 bytes)
-- sequence: ffffffff (4 bytes)
- output_count: 01 (1 bytes)
- Output 0: {34 bytes}
-- value: 84960d0000000000 (8 bytes)
-- script_length: 19 (1 bytes)
-- scriptPubKey: 76a914d5d5959ba3035c57b81e9178a8a34e6e7d9580c888ac (25 bytes)
- block_lock_time: 00000000 (4 bytes)

Signed transaction:
0100000002d4bac71cf9340fd125553fc3d8e9868e21e63089226b7c6cebefbf0a7bef0c2b000000008a47304402202c76a68f7eae79f50034a0a7b3b3dca729f03be1f17c445ad3762ec286a6055402202f8eabbb81a3adc8a6b70ca95dc7972489c6ed28e80be1d8775d00eaf37846640141042d09248cf80095d875561c83adc572f7bae3ff39832f9028b7abd792b4e439b2d522e9b461e8bbaf937c6165a1767b9a105268f013e424e6f7101b042d1dc5edffffffffd4bac71cf9340fd125553fc3d8e9868e21e63089226b7c6cebefbf0a7bef0c2b010000008a47304402205a092cff6c5776e555c4cdbfb8a2dcf696e34fab1202e6d542827b8721c75f56022032b83b3b93f384aaef84b3c0894b5f05917b886ef46f2df61fb5e0c91e62139c0141041489ca134cf898df4e58182cec872126b7a2e635c2db547bda3c27b2b1ea65d145b4563745bac943c8df62be7651a2ec700653c7ebf77d15f8aae48a6e33929fffffffff0184960d00000000001976a914d5d5959ba3035c57b81e9178a8a34e6e7d9580c888ac00000000

### END CREATION OF BITCOIN TRANSACTION





Signed transaction T4:

0100000002d4bac71cf9340fd125553fc3d8e9868e21e63089226b7c6cebefbf0a7bef0c2b000000008a47304402202c76a68f7eae79f50034a0a7b3b3dca729f03be1f17c445ad3762ec286a6055402202f8eabbb81a3adc8a6b70ca95dc7972489c6ed28e80be1d8775d00eaf37846640141042d09248cf80095d875561c83adc572f7bae3ff39832f9028b7abd792b4e439b2d522e9b461e8bbaf937c6165a1767b9a105268f013e424e6f7101b042d1dc5edffffffffd4bac71cf9340fd125553fc3d8e9868e21e63089226b7c6cebefbf0a7bef0c2b010000008a47304402205a092cff6c5776e555c4cdbfb8a2dcf696e34fab1202e6d542827b8721c75f56022032b83b3b93f384aaef84b3c0894b5f05917b886ef46f2df61fb5e0c91e62139c0141041489ca134cf898df4e58182cec872126b7a2e635c2db547bda3c27b2b1ea65d145b4563745bac943c8df62be7651a2ec700653c7ebf77d15f8aae48a6e33929fffffffff0184960d00000000001976a914d5d5959ba3035c57b81e9178a8a34e6e7d9580c888ac00000000





Use http://live.blockcypher.com/btc/decodetx to decode T4 and confirm that it's formatted correctly.

Use http://live.blockcypher.com/btc/pushtx to broadcast T4 to the Bitcoin network.

Result: Txid is:
b533842c4a338227be180a463eea63df6d85ef0bcc358e84000595980dcc0140





Now wait for either
a) T4 to be mined
or
b) T4 to be removed from the memory pools of various visible Bitcoin nodes.



Current datetime:

stjohn@judgement:work$ date

Thu Sep 10 21:51:10 BST 2020




[wait]



stjohn@judgement:work$ date

Thu Sep 10 22:48:56 BST 2020




T4 now has 6+ confirmations.










Next: Create transaction T5, which will transfer bitcoin from A6 back to the online exchange account.



Deposit address at Solidi:
1NBXXLc7443x5KFw7k5jbnHBwM1CNGw6ka




Look up the details of the unspent outputs stored in A6.

stjohn@judgement:work$ python getUTXOsInAddress.py --address 1LVenxwqnmvwjjBdyUByWsD7mXNmJJP2ZF

- utxo 0:
-- txid: b533842c4a338227be180a463eea63df6d85ef0bcc358e84000595980dcc0140
-- previous_output_index: 0
-- satoshiValue: 890500
-- bitcoinValue: 0.008905




Here is the private key with which to sign the input.

P6:
bdd04ba66229d390b565b3aec61ea7aef4863fac98b493d1c6c3e7c6e0d5e391




Generate a new random K value with which to sign T5.

K7:
4526f71a88ae5c4e74e930fb5d1988668c37a1f391d1ab37c09fff773b7ffcc6




Look up current fee rates again. Result: A fee rate of 100 satoshi / byte is estimated to get the transaction mined in the next 3-5 blocks.



In the controls of create_transaction_3.py, set the random_value to be K7 and set the fee rate to be 100.

The fee will be subtracted from the single output value.

	##### START CONTROLS
	# Note: Hex characters in input variable values must be lowercase. 
	random_values = [
		"4526f71a88ae5c4e74e930fb5d1988668c37a1f391d1ab37c09fff773b7ffcc6",
	]
	# random_value must be between 1 and 32 bytes. If random_value_type is "raw_bytes", then random_value must be between 1 and 32 ASCII characters. If random_value_type is "hex_bytes", then random_value must be an even number of hex characters and between 2 and 64 hex characters (1 byte is represented by 2 hex characters). 
	# Note: Every ECDSA signature (one for each input in a transaction) requires new random entropy. 
	# random_value_type options: ["raw_bytes", "hex_bytes"]
	random_value_type = "hex_bytes"
	input_data = [
		{
		"txid": "b533842c4a338227be180a463eea63df6d85ef0bcc358e84000595980dcc0140",
		"previous_output_index": "0",
		"private_key_hex": "bdd04ba66229d390b565b3aec61ea7aef4863fac98b493d1c6c3e7c6e0d5e391",
		#"satoshi_amount": "", 
		"bitcoin_amount": "0.008905", 
		},
	]
	output_data = [
		{
		"address": "1NBXXLc7443x5KFw7k5jbnHBwM1CNGw6ka",
		#"satoshi_amount": "", 
		"bitcoin_amount": "0.008905", 
		},
	]
	# note: all inputs and outputs are assumed to be Pay-To-Public-Key-Hash (P2PKH). 
	change_address = "1NBXXLc7443x5KFw7k5jbnHBwM1CNGw6ka"
	# note: the fee will be subtracted from the amount that is being sent to the change address.
	fee = "" # satoshi
	fee_rate = "100" # satoshi / byte
	# fee_type options: ["fee", "fee_rate"]
	fee_type = "fee_rate"
	##### END CONTROLS





Create and sign the transaction.


stjohn@judgement:work$ python create_transaction_3.py


### START CREATION OF BITCOIN TRANSACTION

- Fee type: fee_rate
- Fee rate: 100.0 (satoshi / byte)
- Number of inputs (i.e. as-yet-unspent outputs): 1
- Number of outputs: 1
- Change address: 1NBXXLc7443x5KFw7k5jbnHBwM1CNGw6ka
- Amount to be sent to the change address: 0.008905
- Input addresses, with total-value-to-be-sent:
-- 1LVenxwqnmvwjjBdyUByWsD7mXNmJJP2ZF: 0.00890500
- Output addresses, with total-value-to-be-received:
-- 1NBXXLc7443x5KFw7k5jbnHBwM1CNGw6ka: 0.00890500
- Total value of all inputs: 0.00890500
- Total value of all outputs: 0.00890500
- Total value of all inputs exactly matches total value of all outputs.
- Estimated transaction size: 223 bytes
- Fee rate: 100.0 (satoshi / byte)
- Calculate 223 * 100.0 and round up to nearest satoshi.
- Final fee: 22300 (satoshi)
- Final fee rate (using estimated transaction size): 100.0000 (satoshi per byte)
- Fee subtracted from amount-to-be-sent-to-change-address.
- New amount to be sent to change address: 868200 (satoshi)
- Size of signed transaction: 223 bytes
- (signed_tx_size - estimated_tx_size): 0 bytes
- Fee rate in signed transaction: 100.0 (satoshi / byte)

Input 0:
Input: {40 bytes unsigned, 66 bytes signable, 179 bytes signed}
- [data] previous_output_hash: 4001cc0d98950500848e35cc0bef856ddf63ea3e460a18be2782334a2c8433b5 (32 bytes)
- [data] previous_output_index: 00000000 (4 bytes)
- [signed form] script_length: 8a (1 bytes)
- [signed form] scriptSig: 473044022057fde87fd838bc87d7ebc3f03d379a9dd6e3fd9591e9de65e1403255be3289720220689084c9edba64d620ed8f5773f2ff18745fef3fcff0d609fb18efe375f6a2f40141040476cfff758b2f351a5a70b45b31ae19895ac07ff0ca33cfe5219e99e8ab2f7c6a168916787da0bae89b7a5200e3c1d0c0a6e4c2df82a816fb23862d2345611d (138 bytes)
- [data] sequence: ffffffff (4 bytes)
- [used for signing] private_key_hex: bdd04ba66229d390b565b3aec61ea7aef4863fac98b493d1c6c3e7c6e0d5e391 (32 bytes)
- [source, goes into scriptSig] public_key_hex: 040476cfff758b2f351a5a70b45b31ae19895ac07ff0ca33cfe5219e99e8ab2f7c6a168916787da0bae89b7a5200e3c1d0c0a6e4c2df82a816fb23862d2345611d (65 bytes)
- [signable form] script_length_scriptPubKey: 19 (1 bytes)
- [signable form] scriptPubKey: 76a914d5d5959ba3035c57b81e9178a8a34e6e7d9580c888ac (25 bytes)
- [more info] address: 1LVenxwqnmvwjjBdyUByWsD7mXNmJJP2ZF
- [more info] previous_output_index_int: 0
- [more info] txid: b533842c4a338227be180a463eea63df6d85ef0bcc358e84000595980dcc0140

Output 0:
Output: {34 bytes}
- [data] value: 683f0d0000000000 (8 bytes)
- [data] script_length: 19 (1 bytes)
- [data] scriptPubKey: 76a914e85847cbba0756cf4b881bd2fc114956fd51b00188ac (25 bytes)
- [more info] address: 1NBXXLc7443x5KFw7k5jbnHBwM1CNGw6ka
- [more info] bitcoin_amount: 0.00868200
- [more info] satoshi_amount: 868200
- [more info] public_key_hash_hex: e85847cbba0756cf4b881bd2fc114956fd51b001

Transaction (unsigned form): {84 bytes}
- version: 01000000 (4 bytes)
- input_count: 01 (1 bytes)
- Input 0: {40 bytes}
-- previous_output_hash: 4001cc0d98950500848e35cc0bef856ddf63ea3e460a18be2782334a2c8433b5 (32 bytes)
-- previous_output_index: 00000000 (4 bytes)
-- script_length: [none] (0 bytes)
-- scriptSig: [none] (0 bytes)
-- sequence: ffffffff (4 bytes)
- output_count: 01 (1 bytes)
- Output 0: {34 bytes}
-- value: 683f0d0000000000 (8 bytes)
-- script_length: 19 (1 bytes)
-- scriptPubKey: 76a914e85847cbba0756cf4b881bd2fc114956fd51b00188ac (25 bytes)
- block_lock_time: 00000000 (4 bytes)

Transaction (signable form 0): {114 bytes}
- version: 01000000 (4 bytes)
- input_count: 01 (1 bytes)
- Input 0 [to be used to sign this signable form]: {66 bytes}
-- previous_output_hash: 4001cc0d98950500848e35cc0bef856ddf63ea3e460a18be2782334a2c8433b5 (32 bytes)
-- previous_output_index: 00000000 (4 bytes)
-- script_length_scriptPubKey: 19 (1 bytes)
-- scriptPubKey: 76a914d5d5959ba3035c57b81e9178a8a34e6e7d9580c888ac (25 bytes)
-- sequence: ffffffff (4 bytes)
- output_count: 01 (1 bytes)
- Output 0: {34 bytes}
-- value: 683f0d0000000000 (8 bytes)
-- script_length: 19 (1 bytes)
-- scriptPubKey: 76a914e85847cbba0756cf4b881bd2fc114956fd51b00188ac (25 bytes)
- block_lock_time: 00000000 (4 bytes)
- hash_type_4_byte: 01000000 (4 bytes)

Transaction (signed form): {223 bytes}
- version: 01000000 (4 bytes)
- input_count: 01 (1 bytes)
- Input 0: {179 bytes}
-- previous_output_hash: 4001cc0d98950500848e35cc0bef856ddf63ea3e460a18be2782334a2c8433b5 (32 bytes)
-- previous_output_index: 00000000 (4 bytes)
-- script_length: 8a (1 bytes)
-- scriptSig: 473044022057fde87fd838bc87d7ebc3f03d379a9dd6e3fd9591e9de65e1403255be3289720220689084c9edba64d620ed8f5773f2ff18745fef3fcff0d609fb18efe375f6a2f40141040476cfff758b2f351a5a70b45b31ae19895ac07ff0ca33cfe5219e99e8ab2f7c6a168916787da0bae89b7a5200e3c1d0c0a6e4c2df82a816fb23862d2345611d (138 bytes)
-- sequence: ffffffff (4 bytes)
- output_count: 01 (1 bytes)
- Output 0: {34 bytes}
-- value: 683f0d0000000000 (8 bytes)
-- script_length: 19 (1 bytes)
-- scriptPubKey: 76a914e85847cbba0756cf4b881bd2fc114956fd51b00188ac (25 bytes)
- block_lock_time: 00000000 (4 bytes)

Signed transaction:
01000000014001cc0d98950500848e35cc0bef856ddf63ea3e460a18be2782334a2c8433b5000000008a473044022057fde87fd838bc87d7ebc3f03d379a9dd6e3fd9591e9de65e1403255be3289720220689084c9edba64d620ed8f5773f2ff18745fef3fcff0d609fb18efe375f6a2f40141040476cfff758b2f351a5a70b45b31ae19895ac07ff0ca33cfe5219e99e8ab2f7c6a168916787da0bae89b7a5200e3c1d0c0a6e4c2df82a816fb23862d2345611dffffffff01683f0d00000000001976a914e85847cbba0756cf4b881bd2fc114956fd51b00188ac00000000

### END CREATION OF BITCOIN TRANSACTION





Signed transaction T5:

01000000014001cc0d98950500848e35cc0bef856ddf63ea3e460a18be2782334a2c8433b5000000008a473044022057fde87fd838bc87d7ebc3f03d379a9dd6e3fd9591e9de65e1403255be3289720220689084c9edba64d620ed8f5773f2ff18745fef3fcff0d609fb18efe375f6a2f40141040476cfff758b2f351a5a70b45b31ae19895ac07ff0ca33cfe5219e99e8ab2f7c6a168916787da0bae89b7a5200e3c1d0c0a6e4c2df82a816fb23862d2345611dffffffff01683f0d00000000001976a914e85847cbba0756cf4b881bd2fc114956fd51b00188ac00000000





Use http://live.blockcypher.com/btc/decodetx to decode T5 and confirm that it's formatted correctly.

Use http://live.blockcypher.com/btc/pushtx to broadcast T5 to the Bitcoin network.

Result: Txid is:
aad6d03ab13203ee7bdfb7e747c5aaef5a60f23c46b87e744176ad7955bd8bb6





Now wait for either
a) T5 to be mined
or
b) T5 to be removed from the memory pools of various visible Bitcoin nodes.



Current datetime:

stjohn@judgement:work$ date

Fri Sep 11 09:10:32 BST 2020




[wait]



stjohn@judgement:work$ date

Fri Sep 11 15:29:00 BST 2020




T5 now has 6+ confirmations.



Final output amount: 0.00868200 bitcoin










Good. That's the end of this project.