edgecase_datafeed1772020-09-12
This is the date at the time of creation of this datafeed article. A checkpoint article containing a hash of this datafeed article may be created on this date or at a later date.14492020-05-28bitcoinb27618deae05910f529240cc6960aeb87f017b12d302327253ee893825ce2bd46321001HtwyqFWNVDoSEVqZwjBRRAV2oEsi8aQXr13MfGs39pR5aEK4iKdoLjVYXKwi6Y3uyPqRecipe_for_managing_the_fee_and_broadcast_of_a_Bitcoin_transaction_#2stjohn_piano2020-09-12no
Parts
- Description
- Notes
- Recipe
- Example
Description
This recipe describes a method of managing the fee and broadcast of a Bitcoin transaction.
If a transaction is not mined, a new version can be constructed with a higher fee. Once the previous version has been cleared from memory pools of accessible Bitcoin nodes, the new version can be broadcast.
Previous version of this recipe:
articleRecipe_for_managing_the_fee_and_broadcast_of_a_Bitcoin_transactionedgecase76Recipe for managing the fee and broadcast of a Bitcoin transaction
Notes
Various points:
- Bitcoin is stored in a Bitcoin address.
- An address holds "unspent outputs". Previous Bitcoin transactions created these outputs and sent them specifically to the address.
- The bitcoin balance of an address is the sum of the values in its unspent outputs.
- A new Bitcoin transaction will use unspent outputs as its inputs.
- When creating a new transaction, only complete inputs can be used. Inputs cannot be broken into smaller inputs prior to spending.
- In a new transaction, any change that you wish to keep can be sent in a new unspent output back to the original address or to another address that you control.
If a transaction disappears from the network (i.e. the memory pools of all public nodes), this doesn't mean that it has vanished permanently. Anyone who stored it can rebroadcast it later - it will still be valid. In order to make it invalid, create a new transaction that uses at least one of the same inputs.
An input in a new transaction is an as-yet-unspent output of a previous transaction. Each unspent output can only ever be spent once. If a transaction is broadcast that uses at least one input that has already been spent, this transaction is invalid and will not be mined.
Recipe
Objectives:
- Fine control of the transaction fee.
- Ability to rebroadcast a new transaction with a higher fee if the previous transaction is not mined within a reasonable time period. This new transaction, if mined, should invalidate the previous transaction.
Relevant links:
-
articleRecipe_for_creating_and_signing_a_standard_Bitcoin_transaction_#2edgecase168Recipe for creating and signing a standard Bitcoin transaction #2
-
articleRecipe_for_creating_and_signing_a_nonstandard_Bitcoin_transaction_#2edgecase172Recipe for creating and signing a nonstandard Bitcoin transaction #2
The
hyperlinkhttp://edgecase.net/pages/other_servicesOther services
page will hopefully include links to active services that can:
- display current Bitcoin fee rates.
- decode / validate a Bitcoin transaction.
- broadcast a transaction to the Bitcoin network.
- look up a transaction in the Bitcoin blockchain and count its confirmations.
1) Gather / choose the required data for a new transaction. Include at least one "change address" output. Inputs should be added as necessary so that the total input value is greater than the total output value. Add enough to pay for the as-yet-unknown transaction fee. Any bitcoin that is left over will be sent to the change address.
2) Look at the current Bitcoin network transaction fee rates. Choose a fee rate for the transaction.
3) Create and sign a transaction with the specified fee rate.
4) Broadcast the transaction to the Bitcoin network.
5) Wait for the transaction to be mined.
Explanation: A node will store unconfirmed transactions in its memory pools for a particular time period. If the transaction is not mined (confirmed) within this period, the node will delete it from its memory pool. This period will vary depending on the node. I have read that the default period is 72 hours (3 days). In my experience, transaction deletions occur in 24-48 hours.
After broadcasting the transaction, wait 3 days + a small delay. If the transaction is mined during this period, stop here, and wait for the transaction to receive 6 confirmations (i.e. be 6 blocks deep into the Bitcoin blockchain). Otherwise, confirm that it has been deleted from the relevant node's memory pool (by looking up the transaction's txid) and continue to step (6).
6) Look at the current Bitcoin network transaction fee rates. Choose a higher fee rate than the one chosen in step (2).
7) Repeat steps (2)-(6) until the transaction is mined. At least one of the inputs should be present in all of these transactions, so that when one of them is mined, the others are invalidated.
Example
I'll summarise a transaction sequence from the previous project
articleCreating_and_signing_a_standard_Bitcoin_transaction_with_two_inputs_and_two_outputsedgecase173Creating and signing a standard Bitcoin transaction with two inputs and two outputs
that demonstrates the process of the creation and broadcast of a new version of a transaction with a higher fee.
Initial conditions:
- I created addresses A1, A2, A3.
Address 1 (A1):
1BB66Gx4833uKx8Lo2k8Mt4TRk42WTr7cZ
A2:
12YCFdpsRDvEHNcj5rsmvJ5G2XXkW1icJP
A3:
1H5SUR7Fv7x252WuJPqBjewwpeHuJ218Ky
Transaction sequence:
- Transaction T1: I used
hyperlinkhttp://solidi.coSolidi
, an online exchange, to transfer 0.01 BTC to address A1. Solidi created a transaction that included this transfer.
-- Txid1:
9d64ba7c5afdb3caa79bb79c35dde09af70b27829241b2823e4ffb918c75d153
- T2_v1 (Transaction 2, version 1): I created a transaction that would transfer the bitcoin in A1 to addresses A2 and A3 (0.005 bitcoin to each, with the A2 output paying the fee). This transaction had a fee rate of 1 satoshi / byte.
-- Txid2_v1:
d03971f787c974bdae8b77fef474567cbc6ae2626d85c36872efc9ddea7383f2
-- Result: T2_v1 was not mined. Within 32 hours, it had been removed from the public nodes that I checked.
- T2_v2: I created another version of T2. This transaction had a fee rate of 100 satoshi / byte.
-- Txid2_v2:
585f054c01139bdae20ff8fa233c4cda47db6d891a387e37dfd56f9cb39d1bea
- Result: T2_v2 was mined with 6+ confirmations in about an hour.
iQIcBAABCgAGBQJfXUaqAAoJECL1OzZgiBhw2/QP/0XxeFMSykuwvNGz5Dsn4KFc
0sKwEsUNeFgJnQzsiV7O57zjERsrE9wLZ8SdGsdQQi7Uy8kf2CJkFuNfECgEJ5x4
mNmYw3jevR4xdLqZKGhUbSi7rcNiyeo6wvYt0vf35vYUodLyRbgwp81Q53kJk5mG
Ccgf32lqgncCXSHGsABdRmsAQkXdsmVhTFkvr72yjwTClAdD5aOuZIPPFIE0Wh+a
THV0n3adEWtik2SL9WnhzMx0nzNS/kKq1iKHga0SHpcD/P9fcJnOpYlI5kG8QADs
Sez/5Y/a2k9oTtBj5BHoD9MPQ+vJlH4sNfHYn1T38VT/UE21SZGwI3RlfBBGmg5b
FVjQ/KVbqbX6DpcUz/M/1B+gvUqQrP/y6udcrKYuUuvTrPPzQ6FAHVkmtmt7Lh5b
LpSBJXslB1il+3W3Phu4YbKMi4QVItu2IdJt4YcLOk60xAOBkVq8FvwKBHPYF7fh
8RavCLU78PkO7UE+tWNecJ40+mZ3oIWrtlG7b/2qt0k9wbXlrhRMxVc7HF4uG2JZ
32+1mR8SqacsvMF2PrRSDPv/Q96aUIKFa85+87AWMPZkKQchuqqulFByJZK4uuAo
gNrKlU5MtwKaLWkxVFzIu6zZirYSuxvzmdGezFu9nZtSi+CLoloxEIx7VfX3m+qS
UoPUtYV8IONy0SAi3J01
=6FwJ