<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://en.bitcoin.it/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Tkerin</id>
	<title>Bitcoin Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://en.bitcoin.it/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Tkerin"/>
	<link rel="alternate" type="text/html" href="https://en.bitcoin.it/wiki/Special:Contributions/Tkerin"/>
	<updated>2026-04-17T10:29:16Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Confirmation&amp;diff=63612</id>
		<title>Confirmation</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Confirmation&amp;diff=63612"/>
		<updated>2017-07-10T19:57:41Z</updated>

		<summary type="html">&lt;p&gt;Tkerin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;After a transaction is broadcast to the Bitcoin network, it may be included in a block that is published to the network.&lt;br /&gt;
When that happens it is said that the transaction has been mined at a depth of 1 block.&lt;br /&gt;
With each subsequent block that is found, the number of blocks deep is increased by one.&lt;br /&gt;
To be secure against [[double spending]], a transaction should not be considered as &#039;&#039;&#039;confirmed&#039;&#039;&#039; until it is a certain number of blocks deep.&lt;br /&gt;
&lt;br /&gt;
=Number of Confirmations=&lt;br /&gt;
&lt;br /&gt;
The classic bitcoin client will show a transaction as &amp;quot;n/unconfirmed&amp;quot; until the transaction is 6 blocks deep.&lt;br /&gt;
Merchants and exchanges who accept [[trade|bitcoins as payment]] can and should set their own threshold as to how many blocks are required until funds are considered confirmed.&lt;br /&gt;
When potential loss due to double spending as nominal, as with very inexpensive or non-fungible items, people may choose not to wait for a transaction to be confirmed, and complete the exchange as soon as it is seen on the network.&lt;br /&gt;
Most [[:Category:Exchanges|exchanges]] and other merchants who bear the risk from double spending require 6 or more blocks.&lt;br /&gt;
&lt;br /&gt;
There is nothing special about the default, often-cited figure of 6 blocks. It was chosen based on the assumption that an attacker is unlikely to amass more than 10% of the hashrate, and that a negligible risk of less than 0.1% is acceptable.&lt;br /&gt;
Both these figures are arbitrary, however;&lt;br /&gt;
6 blocks are overkill for casual attackers, and at the same time powerless against more dedicated attackers with much more than 10% hashrate.&amp;lt;ref&amp;gt;[https://bitcoil.co.il/Doublespend.pdf Analysis of hashrate-based double-spending]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Freshly-mined coins cannot be spent for 100 blocks.&lt;br /&gt;
It is advisable to wait some additional time for a better chance that the transaction will be propagated by all nodes.&lt;br /&gt;
Some older bitcoin clients won&#039;t show generated coins as confirmed until they are 120 blocks deep.&lt;br /&gt;
&lt;br /&gt;
==How Many Confirmations Is Enough==&lt;br /&gt;
&lt;br /&gt;
Transactions with 0/unconfirmed can be reversed with not too much cost via Finney attack and race attack, but in some cases may still be acceptable especially for low-value goods and services, or ones which can be clawed back.&lt;br /&gt;
&lt;br /&gt;
For transactions with confirmations, the website (https://people.xiph.org/~greg/attack_success.html) can be used to calculate the probability of a successful doublespend given a hashrate proportion and number of confirmations. Note that in the reality of bitcoin mining today, more than 6 confirmations are required. (60 confirmations to have &amp;lt;1% odds of succeeding against an entity with 40% hash power). See Section 11 of the (https://bitcoin.org/bitcoin.pdf bitcoin whitepaper) for the AttackerSuccessProbability formula.&lt;br /&gt;
&lt;br /&gt;
Some mining enterprises may hide their hash power across several mining pools. Also mining [[Mining#ASIC_Mining|ASICs]] can be temporarily overclocked to increase their hash power. This is less power-efficient but could be used for a brief burst of hashrate. For maximum safety, it is recommended that for the irreversible sale of items with value comparable to the block reward, a large number of confirmations (144 blocks = 1 day) is required before completing the exchange.&lt;br /&gt;
&lt;br /&gt;
See also: [[Irreversible Transactions]]&lt;br /&gt;
&lt;br /&gt;
=Confirmation Times=&lt;br /&gt;
&lt;br /&gt;
Each additional confirmation is a new [[block]] being found and added to the end of the [[blockchain]].&lt;br /&gt;
&lt;br /&gt;
Miners create blocks by solving the [[proof of work]] for their proposed block. The block interval has an average of 10 minutes but not every block interval is exactly 10 minutes. It follows a statistical process known as a [https://en.wikipedia.org/wiki/Poisson_point_process poisson process], where random events happen with the same probability in each time interval. Another way of expressing this is that the mining process has no memory, at every second a block has the same chance of being found. Poisson processes are well-understood but can be unintuative.&lt;br /&gt;
&lt;br /&gt;
[[File:Block-interval.png|600px|center|alt text]]&lt;br /&gt;
&lt;br /&gt;
There are lots of block intervals with a time less than 10 minutes but then a few block intervals much longer which bump up the average to 10 minutes. So the bitcoin network can get unlucky and a block won&#039;t be found for a whole hour.&lt;br /&gt;
&lt;br /&gt;
[[File:Block-cumulative-interval.png|600px|center|alt text]]&lt;br /&gt;
&lt;br /&gt;
In a 10 minute interval, the probability of a block being found is about 63% (or 1 - e^(-1)). So approximately two-thirds of the time a block will be found in 10 minutes or less. In 30 minutes a block has a 95% chance of being found, which rises to 99.7% if the time interval is 60 minutes.&lt;br /&gt;
&lt;br /&gt;
=See Also=&lt;br /&gt;
&lt;br /&gt;
* [[Blocks]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;/div&gt;</summary>
		<author><name>Tkerin</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Confirmation&amp;diff=63611</id>
		<title>Confirmation</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Confirmation&amp;diff=63611"/>
		<updated>2017-07-10T19:55:57Z</updated>

		<summary type="html">&lt;p&gt;Tkerin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;After a transaction is broadcast to the Bitcoin network, it may be included in a block that is published to the network.&lt;br /&gt;
When that happens it is said that the transaction has been mined at a depth of 1 block.&lt;br /&gt;
With each subsequent block that is found, the number of blocks deep is increased by one.&lt;br /&gt;
To be secure against [[double spending]], a transaction should not be considered as &#039;&#039;&#039;confirmed&#039;&#039;&#039; until it is a certain number of blocks deep.&lt;br /&gt;
&lt;br /&gt;
=Number of Confirmations=&lt;br /&gt;
&lt;br /&gt;
The classic bitcoin client will show a transaction as &amp;quot;n/unconfirmed&amp;quot; until the transaction is 6 blocks deep.&lt;br /&gt;
Merchants and exchanges who accept [[trade|bitcoins as payment]] can and should set their own threshold as to how many blocks are required until funds are considered confirmed.&lt;br /&gt;
When potential loss due to double spending as nominal, as with very inexpensive or non-fungible items, people may choose not to wait for a transaction to be confirmed, and complete the exchange as soon as it is seen on the network.&lt;br /&gt;
Most [[:Category:Exchanges|exchanges]] and other merchants who bear the risk from double spending require 6 or more blocks.&lt;br /&gt;
&lt;br /&gt;
There is nothing special about the default, often-cited figure of 6 blocks. It was chosen based on the assumption that an attacker is unlikely to amass more than 10% of the hashrate, and that a negligible risk of less than 0.1% is acceptable.&lt;br /&gt;
Both these figures are arbitrary, however;&lt;br /&gt;
6 blocks are overkill for casual attackers, and at the same time powerless against more dedicated attackers with much more than 10% hashrate.&amp;lt;ref&amp;gt;[https://bitcoil.co.il/Doublespend.pdf Analysis of hashrate-based double-spending]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Freshly-mined coins cannot be spent for 100 blocks.&lt;br /&gt;
It is advisable to wait some additional time for a better chance that the transaction will be propagated by all nodes.&lt;br /&gt;
Some older bitcoin clients won&#039;t show generated coins as confirmed until they are 120 blocks deep.&lt;br /&gt;
&lt;br /&gt;
==How Many Confirmations Is Enough==&lt;br /&gt;
&lt;br /&gt;
Transactions with 0/unconfirmed can be reversed with not too much cost via Finney attack and race attack, but in some cases may still be acceptable especially for low-value goods and services, or ones which can be clawed back.&lt;br /&gt;
&lt;br /&gt;
For transactions with confirmations, the website (https://people.xiph.org/~greg/attack_success.html) can be used to calculate the probability of a successful doublespend given a hashrate proportion and number of confirmations. Note that in the reality of bitcoin mining today, more than 6 confirmations are required. (60 confirmations to have &amp;lt;1% odds of succeeding against an entity with 40% hash power). See Section 11 of the (https://bitcoin.org/bitcoin.pdf)[bitcoin whitepaper] for the AttackerSuccessProbability formula.&lt;br /&gt;
&lt;br /&gt;
Some mining enterprises may hide their hash power across several mining pools. Also mining [[Mining#ASIC_Mining|ASICs]] can be temporarily overclocked to increase their hash power. This is less power-efficient but could be used for a brief burst of hashrate. For maximum safety, it is recommended that for the irreversible sale of items with value comparable to the block reward, a large number of confirmations (144 blocks = 1 day) is required before completing the exchange.&lt;br /&gt;
&lt;br /&gt;
See also: [[Irreversible Transactions]]&lt;br /&gt;
&lt;br /&gt;
=Confirmation Times=&lt;br /&gt;
&lt;br /&gt;
Each additional confirmation is a new [[block]] being found and added to the end of the [[blockchain]].&lt;br /&gt;
&lt;br /&gt;
Miners create blocks by solving the [[proof of work]] for their proposed block. The block interval has an average of 10 minutes but not every block interval is exactly 10 minutes. It follows a statistical process known as a [https://en.wikipedia.org/wiki/Poisson_point_process poisson process], where random events happen with the same probability in each time interval. Another way of expressing this is that the mining process has no memory, at every second a block has the same chance of being found. Poisson processes are well-understood but can be unintuative.&lt;br /&gt;
&lt;br /&gt;
[[File:Block-interval.png|600px|center|alt text]]&lt;br /&gt;
&lt;br /&gt;
There are lots of block intervals with a time less than 10 minutes but then a few block intervals much longer which bump up the average to 10 minutes. So the bitcoin network can get unlucky and a block won&#039;t be found for a whole hour.&lt;br /&gt;
&lt;br /&gt;
[[File:Block-cumulative-interval.png|600px|center|alt text]]&lt;br /&gt;
&lt;br /&gt;
In a 10 minute interval, the probability of a block being found is about 63% (or 1 - e^(-1)). So approximately two-thirds of the time a block will be found in 10 minutes or less. In 30 minutes a block has a 95% chance of being found, which rises to 99.7% if the time interval is 60 minutes.&lt;br /&gt;
&lt;br /&gt;
=See Also=&lt;br /&gt;
&lt;br /&gt;
* [[Blocks]]&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;/div&gt;</summary>
		<author><name>Tkerin</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Segwit_support&amp;diff=63115</id>
		<title>Segwit support</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Segwit_support&amp;diff=63115"/>
		<updated>2017-06-09T14:35:04Z</updated>

		<summary type="html">&lt;p&gt;Tkerin: added response&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;big&amp;gt;&amp;lt;big&amp;gt;&#039;&#039;&#039;PLEASE NOTE:&#039;&#039;&#039; This list is not yet complete, nor completely vetted by the parties listed for accuracy.&amp;lt;/big&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Developers: Please edit your row (add one if you&#039;re missing) to reflect your positions. If for some reason you don&#039;t already have a wiki account that can edit the page, make an account and ask luke-jr to give it access.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
| {{No}} || doesn&#039;t support (but might or might not go along with it with sufficient community support)&lt;br /&gt;
|-&lt;br /&gt;
| {{Deficient}} || okay with the idea, but considers it to have insufficient community support&lt;br /&gt;
|-&lt;br /&gt;
| {{Evaluating}} || still evaluating the idea&lt;br /&gt;
|-&lt;br /&gt;
| {{Wanting}} || positively likes the idea, but considers it to have insufficient community support&lt;br /&gt;
|-&lt;br /&gt;
| {{Weak}} || better than nothing at all&lt;br /&gt;
|-&lt;br /&gt;
| {{Acceptable}} || it is a workable solution&lt;br /&gt;
|-&lt;br /&gt;
| {{Prefer}} || it is what he would choose if it was only up to him and no outside influences&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- README: please keep alphabetically ordered by surname! --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that support for BIP148 does not mean developers support merging it into Core.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
! rowspan=2 | Developer&lt;br /&gt;
! Segwit itself&lt;br /&gt;
! colspan=3 | Deployment methods&lt;br /&gt;
! colspan=2 | Hardfork bundles (Silbert agreement)&lt;br /&gt;
|-&lt;br /&gt;
! [https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki BIP 141] !! [https://github.com/bitcoin/bips/blob/master/bip-0148.mediawiki BIP 148] !! [https://github.com/bitcoin/bips/blob/master/bip-0149.mediawiki BIP 149] !! [https://github.com/bitcoin/bips/blob/master/bip-0091.mediawiki BIP 91] || Segwit2x || [https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-May/014445.html COOP]&lt;br /&gt;
|-&lt;br /&gt;
| ฿tcDrak || {{Prefer}} || {{Acceptable}} || {{Acceptable}} || {{No}} || ||&lt;br /&gt;
|-&lt;br /&gt;
| Andrew Chow || {{Prefer}} || {{Prefer}} || {{Acceptable}} || {{Weak}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Matt Corallo || {{Prefer}} || {{No}} || || {{Acceptable}} || ||&lt;br /&gt;
|-&lt;br /&gt;
| Johnathan Corgan || {{Prefer}} || {{Prefer}} || {{Acceptable}} || {{No}} || {{No}} || {{Evaluating}}&lt;br /&gt;
|-&lt;br /&gt;
| Suhas Daftuar || {{Prefer}} || {{No}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Luke Dashjr || {{Prefer}} || {{Prefer}} || {{No}} || {{Acceptable}} || {{No}} || {{Deficient}}&lt;br /&gt;
|-&lt;br /&gt;
| Christian Decker || {{Prefer}} || {{Acceptable}} ||  ||  || || &lt;br /&gt;
|-&lt;br /&gt;
| Nicolas Dorier || {{Prefer}} || {{Acceptable}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Marco Falke || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Michael Ford || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Mark Friedenbach || {{Prefer}} || {{Acceptable}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Pavel Janik || {{Prefer}} || || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Thomas Kerin || {{Prefer}} || {{Wanting}} || {{Prefer}} || {{Weak}} || {{No}} || {{No}}&lt;br /&gt;
|-&lt;br /&gt;
| Johnson Lau || {{Prefer}} || {{Wanting}} || {{Acceptable}} || {{Acceptable}} || ||&lt;br /&gt;
|-&lt;br /&gt;
| Eric Lombrozo || {{Prefer}} || {{Acceptable}} || {{Evaluating}} || {{No}} || {{Evaluating}} || {{Evaluating}}&lt;br /&gt;
|-&lt;br /&gt;
| Greg Maxwell || {{Prefer}} || {{No}} || {{Acceptable}} || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Alex Morcos || {{Prefer}} || {{Deficient}} || {{Acceptable}} || {{Weak}} || {{No}} ||&lt;br /&gt;
|-&lt;br /&gt;
| Rusty Russell || {{Prefer}} || {{Prefer}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Jonas Schnelli || {{Prefer}} || {{Wanting}} || {{Acceptable}} || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Patrick Strateman || {{Prefer}} ||  || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Jorge Timon || {{Prefer}} || {{No}} || {{Prefer}} || {{Deficient}} || {{Evaluating}} ||&lt;br /&gt;
|-&lt;br /&gt;
| Peter Todd || {{Prefer}} || {{Acceptable}} || || || ||&lt;br /&gt;
|-&lt;br /&gt;
| Wladimir van der Laan || {{Prefer}} || {{Prefer}} || {{Acceptable}} || {{Acceptable}} || {{No}} || {{No}}&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Tkerin</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Protocol_documentation&amp;diff=59575</id>
		<title>Protocol documentation</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Protocol_documentation&amp;diff=59575"/>
		<updated>2015-12-12T00:50:04Z</updated>

		<summary type="html">&lt;p&gt;Tkerin: Correct the type for tx.version - it&amp;#039;s actually a signed integer&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page &#039;&#039;describes&#039;&#039; the behavior of the [[Original Bitcoin client|reference client]]. The Bitcoin protocol is specified by the behavior of the reference client, not by this page. In particular, while this page is quite complete in describing the network protocol, it does not attempt to list all of the rules for block or transaction validity.&lt;br /&gt;
&lt;br /&gt;
Type names used in this documentation are from the C99 standard.&lt;br /&gt;
&lt;br /&gt;
For protocol used in mining, see [[getblocktemplate]].&lt;br /&gt;
&lt;br /&gt;
==Common standards==&lt;br /&gt;
&lt;br /&gt;
=== Hashes ===&lt;br /&gt;
&lt;br /&gt;
Usually, when a hash is computed within bitcoin, it is computed twice. Most of the time [http://en.wikipedia.org/wiki/SHA-2 SHA-256] hashes are used, however [http://en.wikipedia.org/wiki/RIPEMD RIPEMD-160] is also used when a shorter hash is desirable (for example when creating a bitcoin address).&lt;br /&gt;
&lt;br /&gt;
Example of double-SHA-256 encoding of string &amp;quot;hello&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 hello&lt;br /&gt;
 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 (first round of sha-256)&lt;br /&gt;
 9595c9df90075148eb06860365df33584b75bff782a510c6cd4883a419833d50 (second round of sha-256)&lt;br /&gt;
&lt;br /&gt;
For bitcoin addresses (RIPEMD-160) this would give:&lt;br /&gt;
&lt;br /&gt;
 hello&lt;br /&gt;
 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 (first round is sha-256)&lt;br /&gt;
 b6a9c8c230722b7c748331a8b450f05566dc7d0f (with ripemd-160)&lt;br /&gt;
&lt;br /&gt;
=== Merkle Trees ===&lt;br /&gt;
&lt;br /&gt;
Merkle trees are binary trees of hashes. Merkle trees in bitcoin use a &#039;&#039;&#039;double&#039;&#039;&#039; SHA-256, the SHA-256 hash of the SHA-256 hash of something.&lt;br /&gt;
&lt;br /&gt;
If, when forming a row in the tree (other than the root of the tree), it would have an odd number of elements, the final double-hash is duplicated to ensure that the row has an even number of hashes.&lt;br /&gt;
&lt;br /&gt;
First form the bottom row of the tree with the ordered double-SHA-256 hashes of the byte streams of the transactions in the block.&lt;br /&gt;
&lt;br /&gt;
Then the row above it consists of half that number of hashes.  Each entry is the double-SHA-256 of the 64-byte concatenation of the corresponding two hashes below it in the tree.&lt;br /&gt;
&lt;br /&gt;
This procedure repeats recursively until we reach a row consisting of just a single double-hash.  This is the &#039;&#039;&#039;Merkle root&#039;&#039;&#039; of the tree.&lt;br /&gt;
&lt;br /&gt;
For example, imagine a block with three transactions &#039;&#039;a&#039;&#039;, &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039;.   The Merkle tree is: &lt;br /&gt;
&lt;br /&gt;
 d1 = dhash(a)&lt;br /&gt;
 d2 = dhash(b)&lt;br /&gt;
 d3 = dhash(c)&lt;br /&gt;
 d4 = dhash(c)            # a, b, c are 3. that&#039;s an odd number, so we take the c twice&lt;br /&gt;
 &lt;br /&gt;
 d5 = dhash(d1 concat d2)&lt;br /&gt;
 d6 = dhash(d3 concat d4)&lt;br /&gt;
 &lt;br /&gt;
 d7 = dhash(d5 concat d6)&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
 &lt;br /&gt;
 dhash(a) = sha256(sha256(a))&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;d7&#039;&#039; is the Merkle root of the 3 transactions in this block.&lt;br /&gt;
&lt;br /&gt;
Note: Hashes in Merkle Tree displayed in the [[Block Explorer]] are of little-endian notation. For some implementations and [http://www.fileformat.info/tool/hash.htm calculations], the bits need to be reversed before they are hashed, and again after the hashing operation.&lt;br /&gt;
&lt;br /&gt;
=== Signatures ===&lt;br /&gt;
&lt;br /&gt;
Bitcoin uses [http://en.wikipedia.org/wiki/Elliptic_curve_cryptography Elliptic Curve] [http://en.wikipedia.org/wiki/Digital_Signature_Algorithm Digital Signature Algorithm] ([http://en.wikipedia.org/wiki/Elliptic_Curve_DSA ECDSA]) to sign transactions. &lt;br /&gt;
&lt;br /&gt;
For [[ECDSA]] the secp256k1 curve from http://www.secg.org/collateral/sec2_final.pdf is used.&lt;br /&gt;
&lt;br /&gt;
Public keys (in scripts) are given as 04 &amp;lt;x&amp;gt; &amp;lt;y&amp;gt; where &#039;&#039;x&#039;&#039; and &#039;&#039;y&#039;&#039; are 32 byte big-endian integers representing the coordinates of a point on the curve or in compressed form given as &amp;lt;sign&amp;gt; &amp;lt;x&amp;gt; where &amp;lt;sign&amp;gt; is 0x02 if &#039;&#039;y&#039;&#039; is even and 0x03 if &#039;&#039;y&#039;&#039; is odd.&lt;br /&gt;
&lt;br /&gt;
Signatures use [http://en.wikipedia.org/wiki/Distinguished_Encoding_Rules DER encoding] to pack the &#039;&#039;r&#039;&#039; and &#039;&#039;s&#039;&#039; components into a single byte stream (this is also what OpenSSL produces by default).&lt;br /&gt;
&lt;br /&gt;
=== Transaction Verification ===&lt;br /&gt;
Transactions are cryptographically signed records that reassign ownership of Bitcoins to new addresses.  Transactions have &#039;&#039;inputs&#039;&#039; - records which reference the funds from other previous transactions - and &#039;&#039;outputs&#039;&#039; - records which determine the new owner of the transferred Bitcoins, and which will be referenced as inputs in future transactions as those funds are respent.&lt;br /&gt;
&lt;br /&gt;
Each &#039;&#039;input&#039;&#039; must have a cryptographic digital signature that unlocks the funds from the prior transaction.  Only the person possessing the appropriate [[private key]] is able to create a satisfactory signature; this in effect ensures that funds can only be spent by their owners.&lt;br /&gt;
&lt;br /&gt;
Each &#039;&#039;output&#039;&#039; determines which Bitcoin address (or other criteria, see [[Script]]) is the recipient of the funds.&lt;br /&gt;
&lt;br /&gt;
In a transaction, the sum of all inputs must be equal to or greater than the sum of all outputs.  If the inputs exceed the outputs, the difference is considered a [[transaction fee]], and is redeemable by whoever first includes the transaction into the block chain.&lt;br /&gt;
&lt;br /&gt;
A special kind of transaction, called a [[coinbase transaction]], has no inputs.  It is created by [[miners]], and there is one coinbase transaction per block.  Because each block comes with a reward of newly created Bitcoins (e.g. 50 BTC for the first 210,000 blocks), the first transaction of a block is, with few exceptions, the transaction that grants those coins to their recipient (the miner).  In addition to the newly created Bitcoins, the coinbase transaction is also used for assigning the recipient of any transaction fees that were paid within the other transactions being included in the same block.  The coinbase transaction can assign the entire reward to a single Bitcoin address, or split it in portions among multiple addresses, just like any other transaction.  Coinbase transactions always contain outputs totalling the sum of the block reward plus all transaction fees collected from the other transactions in the same block.&lt;br /&gt;
&lt;br /&gt;
The [[coinbase transaction]] in block zero cannot be spent. This is due to a quirk of the reference client implementation that would open the potential for a block chain fork if some nodes accepted the spend and others did not&amp;lt;ref&amp;gt;[http://bitcointalk.org/index.php?topic=119645.msg1288552#msg1288552 Block 0 Network Fork]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Most Bitcoin outputs encumber the newly transferred coins with a single ECDSA private key.  The actual record saved with inputs and outputs isn&#039;t necessarily a key, but a &#039;&#039;script&#039;&#039;.  Bitcoin uses an interpreted scripting system to determine whether an output&#039;s criteria have been satisfied, with which more complex operations are possible, such as outputs that require two ECDSA signatures, or two-of-three-signature schemes.  An output that references a single Bitcoin address is a &#039;&#039;typical&#039;&#039; output; an output actually contains this information in the form of a script that requires a single ECDSA signature (see [[OP_CHECKSIG]]).  The output script specifies what must be provided to unlock the funds later, and when the time comes in the future to spend the transaction in another input, that input must provide all of the thing(s) that satisfy the requirements defined by the original output script.&lt;br /&gt;
&lt;br /&gt;
=== Addresses ===&lt;br /&gt;
&lt;br /&gt;
A bitcoin address is in fact the hash of a ECDSA public key, computed this way:&lt;br /&gt;
&lt;br /&gt;
 Version = 1 byte of 0 (zero); on the test network, this is 1 byte of 111&lt;br /&gt;
 Key hash = Version concatenated with RIPEMD-160(SHA-256(public key))&lt;br /&gt;
 Checksum = 1st 4 bytes of SHA-256(SHA-256(Key hash))&lt;br /&gt;
 Bitcoin Address = Base58Encode(Key hash concatenated with Checksum)&lt;br /&gt;
&lt;br /&gt;
The Base58 encoding used is home made, and has some differences. Especially, leading zeroes are kept as single zeroes when conversion happens.&lt;br /&gt;
&lt;br /&gt;
== Common structures ==&lt;br /&gt;
&lt;br /&gt;
Almost all integers are encoded in little endian. Only IP or port number are encoded big endian.&lt;br /&gt;
&lt;br /&gt;
=== Message structure ===&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || magic || uint32_t || Magic value indicating message origin network, and used to seek to next message when stream state is unknown&lt;br /&gt;
|-&lt;br /&gt;
| 12 || command || char[12] || ASCII string identifying the packet content, NULL padded (non-NULL padding results in packet rejected)&lt;br /&gt;
|-&lt;br /&gt;
| 4 || length || uint32_t || Length of payload in number of bytes&lt;br /&gt;
|-&lt;br /&gt;
| 4 || checksum || uint32_t || First 4 bytes of sha256(sha256(payload))&lt;br /&gt;
|-&lt;br /&gt;
| ? || payload || uchar[] || The actual data&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Known magic values:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Network !! Magic value !! Sent over wire as&lt;br /&gt;
|-&lt;br /&gt;
| main || 0xD9B4BEF9 || F9 BE B4 D9&lt;br /&gt;
|-&lt;br /&gt;
| testnet || 0xDAB5BFFA || FA BF B5 DA&lt;br /&gt;
|-&lt;br /&gt;
| testnet3 || 0x0709110B || 0B 11 09 07&lt;br /&gt;
|-&lt;br /&gt;
| namecoin || 0xFEB4BEF9 || F9 BE B4 FE&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Variable length integer ===&lt;br /&gt;
&lt;br /&gt;
Integer can be encoded depending on the represented value to save space.&lt;br /&gt;
Variable length integers always precede an array/vector of a type of data that may vary in length.&lt;br /&gt;
Longer numbers are encoded in little endian.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Storage length !! Format&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt; 0xFD || 1 || uint8_t&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;= 0xFFFF || 3 || 0xFD followed by the length as uint16_t&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;= 0xFFFF FFFF || 5 || 0xFE followed by the length as uint32_t&lt;br /&gt;
|-&lt;br /&gt;
| - || 9 || 0xFF followed by the length as uint64_t&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If you&#039;re reading the Satoshi client code (BitcoinQT) it refers to this encoding as a &amp;quot;CompactSize&amp;quot;. Modern BitcoinQT also has the CVarInt class which implements an even more compact integer for the purpose of local storage (which is incompatible with &amp;quot;CompactSize&amp;quot; described here). CVarInt is not a part of the protocol.&lt;br /&gt;
&lt;br /&gt;
=== Variable length string ===&lt;br /&gt;
&lt;br /&gt;
Variable length string can be stored using a variable length integer followed by the string itself.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || length || [[Protocol_documentation#Variable_length_integer|var_int]] || Length of the string&lt;br /&gt;
|-&lt;br /&gt;
| ? || string || char[] || The string itself (can be empty)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Network address ===&lt;br /&gt;
&lt;br /&gt;
When a network address is needed somewhere, this structure is used. Network addresses are not prefixed with a timestamp in the version message.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || time || uint32 || the Time (version &amp;gt;= 31402). &#039;&#039;&#039;Not present in version message.&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
| 8 || services || uint64_t || same service(s) listed in [[#version|version]]&lt;br /&gt;
|-&lt;br /&gt;
| 16 || IPv6/4 || char[16] || IPv6 address. Network byte order. The original client only supported IPv4 and only read the last 4 bytes to get the IPv4 address. However, the IPv4 address is written into the message as a 16 byte [http://en.wikipedia.org/wiki/IPv6#IPv4-mapped_IPv6_addresses IPv4-mapped IPv6 address]&lt;br /&gt;
(12 bytes &#039;&#039;00 00 00 00  00 00 00 00  00 00 FF FF&#039;&#039;, followed by the 4 bytes of the IPv4 address).&lt;br /&gt;
|-&lt;br /&gt;
| 2 || port || uint16_t || port number, network byte order&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Hexdump example of Network address structure&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000   01 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ................&lt;br /&gt;
0010   00 00 FF FF 0A 00 00 01  20 8D                    ........ .&lt;br /&gt;
&lt;br /&gt;
Network address:&lt;br /&gt;
 01 00 00 00 00 00 00 00                         - 1 (NODE_NETWORK: see services listed under version command)&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 FF FF 0A 00 00 01 - IPv6: ::ffff:a00:1 or IPv4: 10.0.0.1&lt;br /&gt;
 20 8D                                           - Port 8333&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inventory Vectors ===&lt;br /&gt;
&lt;br /&gt;
Inventory vectors are used for notifying other nodes about objects they have or data which is being requested.&lt;br /&gt;
&lt;br /&gt;
Inventory vectors consist of the following data format:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || type || uint32_t || Identifies the object type linked to this inventory&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash || char[32] || Hash of the object&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The object type is currently defined as one of the following possibilities:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || ERROR || Any data of with this number may be ignored&lt;br /&gt;
|-&lt;br /&gt;
| 1 || MSG_TX || Hash is related to a transaction&lt;br /&gt;
|-&lt;br /&gt;
| 2 || MSG_BLOCK || Hash is related to a data block&lt;br /&gt;
|-&lt;br /&gt;
| 3 || MSG_FILTERED_BLOCK || Hash of a block header; identical to MSG_BLOCK.  When used in a getdata message, this indicates the reply should be a merkleblock message rather than a block message; this only works if a bloom filter has been set.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Other Data Type values are considered reserved for future implementations.&lt;br /&gt;
&lt;br /&gt;
=== Block Headers ===&lt;br /&gt;
&lt;br /&gt;
Block headers are sent in a headers packet in response to a getheaders message.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || int32_t || Block version information (note, this is signed)&lt;br /&gt;
|-&lt;br /&gt;
| 32 || prev_block || char[32] || The hash value of the previous block this particular block references&lt;br /&gt;
|-&lt;br /&gt;
| 32 || merkle_root || char[32] || The reference to a Merkle tree collection which is a hash of all transactions related to this block&lt;br /&gt;
|-&lt;br /&gt;
| 4 || timestamp || uint32_t || A timestamp recording when this block was created (Will overflow in 2106&amp;lt;ref&amp;gt;https://en.wikipedia.org/wiki/Unix_time#Notable_events_in_Unix_time&amp;lt;/ref&amp;gt;)&lt;br /&gt;
|-&lt;br /&gt;
| 4 || bits || uint32_t || The calculated difficulty target being used for this block&lt;br /&gt;
|-&lt;br /&gt;
| 4 || nonce || uint32_t || The nonce used to generate this block… to allow variations of the header and compute different hashes&lt;br /&gt;
|-&lt;br /&gt;
| 1 || txn_count || [[Protocol_documentation#Variable_length_integer|var_int]] || Number of transaction entries, this value is always 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
cf. [[Block hashing algorithm]]&lt;br /&gt;
&lt;br /&gt;
== Message types ==&lt;br /&gt;
&lt;br /&gt;
=== version ===&lt;br /&gt;
&lt;br /&gt;
When a node creates an outgoing connection, it will immediately [[Version Handshake|advertise]] its version. The remote node will respond with its version. No further communication is possible until both peers have exchanged their version.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || int32_t || Identifies protocol version being used by the node&lt;br /&gt;
|-&lt;br /&gt;
| 8 || services || uint64_t || bitfield of features to be enabled for this connection&lt;br /&gt;
|-&lt;br /&gt;
| 8 || timestamp || int64_t || standard UNIX timestamp in seconds&lt;br /&gt;
|-&lt;br /&gt;
| 26 || addr_recv || [[#Network address|net_addr]] || The network address of the node receiving this message&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;4&amp;quot;| Fields below require version ≥ 106&lt;br /&gt;
|-&lt;br /&gt;
| 26 || addr_from || [[#Network address|net_addr]] || The network address of the node emitting this message&lt;br /&gt;
|-&lt;br /&gt;
| 8 || nonce || uint64_t || Node random nonce, randomly generated every time a version packet is sent. This nonce is used to detect connections to self.&lt;br /&gt;
|-&lt;br /&gt;
| ? || user_agent || [[#Variable length string|var_str]] || [https://github.com/bitcoin/bips/blob/master/bip-0014.mediawiki User Agent] (0x00 if string is 0 bytes long)&lt;br /&gt;
|-&lt;br /&gt;
| 4 || start_height || int32_t || The last block received by the emitting node&lt;br /&gt;
|-&lt;br /&gt;
|colspan=&amp;quot;4&amp;quot;| Fields below require version ≥ 70001&lt;br /&gt;
|-&lt;br /&gt;
| 1 || relay || bool || Whether the remote peer should announce relayed transactions or not, see [https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki BIP 0037]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;verack&amp;quot; packet shall be sent if the version packet was accepted.&lt;br /&gt;
&lt;br /&gt;
The following services are currently assigned:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 1 || NODE_NETWORK || This node can be asked for full blocks instead of just headers.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Hexdump example of version message (OBSOLETE EXAMPLE: This example lacks a checksum and user-agent):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000   F9 BE B4 D9 76 65 72 73  69 6F 6E 00 00 00 00 00   ....version.....&lt;br /&gt;
0010   55 00 00 00 9C 7C 00 00  01 00 00 00 00 00 00 00   U....|..........&lt;br /&gt;
0020   E6 15 10 4D 00 00 00 00  01 00 00 00 00 00 00 00   ...M............&lt;br /&gt;
0030   00 00 00 00 00 00 00 00  00 00 FF FF 0A 00 00 01   ................&lt;br /&gt;
0040   20 8D 01 00 00 00 00 00  00 00 00 00 00 00 00 00   ................&lt;br /&gt;
0050   00 00 00 00 FF FF 0A 00  00 02 20 8D DD 9D 20 2C   .......... ... ,&lt;br /&gt;
0060   3A B4 57 13 00 55 81 01  00                        :.W..U...&lt;br /&gt;
&lt;br /&gt;
Message header:&lt;br /&gt;
 F9 BE B4 D9                                                                   - Main network magic bytes&lt;br /&gt;
 76 65 72 73 69 6F 6E 00 00 00 00 00                                           - &amp;quot;version&amp;quot; command&lt;br /&gt;
 55 00 00 00                                                                   - Payload is 85 bytes long&lt;br /&gt;
                                                                               - No checksum in version message until 20 February 2012. See https://bitcointalk.org/index.php?topic=55852.0&lt;br /&gt;
Version message:&lt;br /&gt;
 9C 7C 00 00                                                                   - 31900 (version 0.3.19)&lt;br /&gt;
 01 00 00 00 00 00 00 00                                                       - 1 (NODE_NETWORK services)&lt;br /&gt;
 E6 15 10 4D 00 00 00 00                                                       - Mon Dec 20 21:50:14 EST 2010&lt;br /&gt;
 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 0A 00 00 01 20 8D - Recipient address info - see Network Address&lt;br /&gt;
 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 0A 00 00 02 20 8D - Sender address info - see Network Address&lt;br /&gt;
 DD 9D 20 2C 3A B4 57 13                                                       - Node random unique ID&lt;br /&gt;
 00                                                                            - &amp;quot;&amp;quot; sub-version string (string is 0 bytes long)&lt;br /&gt;
 55 81 01 00                                                                   - Last block sending node has is block #98645&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And here&#039;s a modern (60002) protocol version client advertising itself to a local peer...&lt;br /&gt;
&lt;br /&gt;
Newer protocol includes the checksum now, this is from a mainline (satoshi) client during &lt;br /&gt;
an outgoing connection to another local client, notice that it does not fill out the &lt;br /&gt;
address information at all when the source or destination is &amp;quot;unroutable&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
0000   f9 be b4 d9 76 65 72 73 69 6f 6e 00 00 00 00 00  ....version.....&lt;br /&gt;
0010   64 00 00 00 35 8d 49 32 62 ea 00 00 01 00 00 00  d...5.I2b.......&lt;br /&gt;
0020   00 00 00 00 11 b2 d0 50 00 00 00 00 01 00 00 00  .......P........&lt;br /&gt;
0030   00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff  ................&lt;br /&gt;
0040   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................&lt;br /&gt;
0050   00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00  ................&lt;br /&gt;
0060   3b 2e b3 5d 8c e6 17 65 0f 2f 53 61 74 6f 73 68  ;..]...e./Satosh&lt;br /&gt;
0070   69 3a 30 2e 37 2e 32 2f c0 3e 03 00              i:0.7.2/.&amp;gt;..&lt;br /&gt;
&lt;br /&gt;
Message Header:&lt;br /&gt;
 F9 BE B4 D9                                                                   - Main network magic bytes&lt;br /&gt;
 76 65 72 73 69 6F 6E 00 00 00 00 00                                           - &amp;quot;version&amp;quot; command&lt;br /&gt;
 64 00 00 00                                                                   - Payload is 100 bytes long&lt;br /&gt;
 3B 64 8D 5A                                                                   - payload checksum&lt;br /&gt;
&lt;br /&gt;
Version message:&lt;br /&gt;
 62 EA 00 00                                                                   - 60002 (protocol version 60002)&lt;br /&gt;
 01 00 00 00 00 00 00 00                                                       - 1 (NODE_NETWORK services)&lt;br /&gt;
 11 B2 D0 50 00 00 00 00                                                       - Tue Dec 18 10:12:33 PST 2012&lt;br /&gt;
 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 00 00 00 00 00 00 - Recipient address info - see Network Address&lt;br /&gt;
 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 00 00 00 00 00 00 - Sender address info - see Network Address&lt;br /&gt;
 3B 2E B3 5D 8C E6 17 65                                                       - Node ID&lt;br /&gt;
 0F 2F 53 61 74 6F 73 68 69 3A 30 2E 37 2E 32 2F                               - &amp;quot;/Satoshi:0.7.2/&amp;quot; sub-version string (string is 15 bytes long)&lt;br /&gt;
 C0 3E 03 00                                                                   - Last block sending node has is block #212672&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== verack ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;verack&#039;&#039; message is sent in reply to &#039;&#039;[[#version|version]]&#039;&#039;.  This message consists of only a [[#Message structure|message header]] with the command string &amp;quot;verack&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Hexdump of the verack message:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000   F9 BE B4 D9 76 65 72 61  63 6B 00 00 00 00 00 00   ....verack......&lt;br /&gt;
0010   00 00 00 00 5D F6 E0 E2                            ........&lt;br /&gt;
&lt;br /&gt;
Message header:&lt;br /&gt;
 F9 BE B4 D9                          - Main network magic bytes&lt;br /&gt;
 76 65 72 61  63 6B 00 00 00 00 00 00 - &amp;quot;verack&amp;quot; command&lt;br /&gt;
 00 00 00 00                          - Payload is 0 bytes long&lt;br /&gt;
 5D F6 E0 E2                          - Checksum&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== addr ===&lt;br /&gt;
&lt;br /&gt;
Provide information on known nodes of the network. Non-advertised nodes should be forgotten after typically 3 hours&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || count || [[Protocol_documentation#Variable_length_integer|var_int]] || Number of address entries (max: 1000)&lt;br /&gt;
|-&lt;br /&gt;
| 30x? || addr_list || (uint32_t + [[#Network address|net_addr]])[] || Address of other nodes on the network. version &amp;lt; 209 will only read the first one. The uint32_t is a timestamp (see note below).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: Starting version 31402, addresses are prefixed with a timestamp. If no timestamp is present, the addresses should not be relayed to other peers, unless it is indeed confirmed they are up.&lt;br /&gt;
&lt;br /&gt;
Hexdump example of &#039;&#039;addr&#039;&#039; message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0000   F9 BE B4 D9 61 64 64 72  00 00 00 00 00 00 00 00   ....addr........&lt;br /&gt;
0010   1F 00 00 00 ED 52 39 9B  01 E2 15 10 4D 01 00 00   .....R9.....M...&lt;br /&gt;
0020   00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 FF   ................&lt;br /&gt;
0030   FF 0A 00 00 01 20 8D                               ..... .&lt;br /&gt;
&lt;br /&gt;
Message Header:&lt;br /&gt;
 F9 BE B4 D9                                     - Main network magic bytes&lt;br /&gt;
 61 64 64 72  00 00 00 00 00 00 00 00            - &amp;quot;addr&amp;quot;&lt;br /&gt;
 1F 00 00 00                                     - payload is 31 bytes long&lt;br /&gt;
 ED 52 39 9B                                     - checksum of payload&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
 01                                              - 1 address in this message&lt;br /&gt;
&lt;br /&gt;
Address:&lt;br /&gt;
 E2 15 10 4D                                     - Mon Dec 20 21:50:10 EST 2010 (only when version is &amp;gt;= 31402)&lt;br /&gt;
 01 00 00 00 00 00 00 00                         - 1 (NODE_NETWORK service - see version message)&lt;br /&gt;
 00 00 00 00 00 00 00 00 00 00 FF FF 0A 00 00 01 - IPv4: 10.0.0.1, IPv6: ::ffff:10.0.0.1 (IPv4-mapped IPv6 address)&lt;br /&gt;
 20 8D                                           - port 8333&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== inv ===&lt;br /&gt;
&lt;br /&gt;
Allows a node to advertise its knowledge of one or more objects. It can be received unsolicited, or in reply to &#039;&#039;getblocks&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Payload (maximum 50,000 entries, which is just over 1.8 megabytes):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || count || [[Protocol_documentation#Variable_length_integer|var_int]] || Number of inventory entries&lt;br /&gt;
|-&lt;br /&gt;
| 36x? || inventory || [[Protocol specification#Inventory Vectors|inv_vect]][] || Inventory vectors&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== getdata ===&lt;br /&gt;
&lt;br /&gt;
getdata is used in response to inv, to retrieve the content of a specific object, and is usually sent after receiving an &#039;&#039;inv&#039;&#039; packet, after filtering known elements. It can be used to retrieve transactions, but only if they are in the memory pool or relay set - arbitrary access to transactions in the chain is not allowed to avoid having clients start to depend on nodes having full transaction indexes (which modern nodes do not).&lt;br /&gt;
&lt;br /&gt;
Payload (maximum 50,000 entries, which is just over 1.8 megabytes):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || count || [[Protocol_documentation#Variable_length_integer|var_int]] || Number of inventory entries&lt;br /&gt;
|-&lt;br /&gt;
| 36x? || inventory || [[Protocol specification#Inventory Vectors|inv_vect]][] || Inventory vectors&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== notfound ===&lt;br /&gt;
&lt;br /&gt;
notfound is a response to a getdata, sent if any requested data items could not be relayed, for example, because the requested transaction was not in the memory pool or relay set.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || count || [[Protocol_documentation#Variable_length_integer|var_int]] || Number of inventory entries&lt;br /&gt;
|-&lt;br /&gt;
| 36x? || inventory || [[Protocol specification#Inventory Vectors|inv_vect]][] || Inventory vectors&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== getblocks ===&lt;br /&gt;
&lt;br /&gt;
Return an &#039;&#039;inv&#039;&#039; packet containing the list of blocks starting right after the last known hash in the block locator object, up to hash_stop or 500 blocks, whichever comes first. &lt;br /&gt;
&lt;br /&gt;
The locator hashes are processed by a node in the order as they appear in the message. If a block hash is found in the node&#039;s main chain, the list of its children is returned back via the &#039;&#039;inv&#039;&#039; message and the remaining locators are ignored, no matter if the requested limit was reached, or not.&lt;br /&gt;
&lt;br /&gt;
To receive the next blocks hashes, one needs to issue getblocks again with a new block locator object. Keep in mind that some clients may provide blocks which are invalid if the block locator object contains a hash on the invalid branch.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || the protocol version&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || hash count || [[Protocol_documentation#Variable_length_integer|var_int]] || number of block locator hash entries&lt;br /&gt;
|-&lt;br /&gt;
| 32+ || block locator hashes || char[32] || block locator object; newest back to genesis block (dense to start, but then sparse)&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash_stop || char[32] || hash of the last desired block; set to zero to get as many blocks as possible (500)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To create the block locator hashes, keep pushing hashes until you go back to the genesis block. After pushing 10 hashes back, the step backwards doubles every loop:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// From libbitcoin which is under AGPL&lt;br /&gt;
std::vector&amp;lt;size_t&amp;gt; block_locator_indices(int top_depth)&lt;br /&gt;
{&lt;br /&gt;
    // Start at max_depth&lt;br /&gt;
    std::vector&amp;lt;size_t&amp;gt; indices;&lt;br /&gt;
    // Push last 10 indices first&lt;br /&gt;
    size_t step = 1, start = 0;&lt;br /&gt;
    for (int i = top_depth; i &amp;gt; 0; i -= step, ++start)&lt;br /&gt;
    {&lt;br /&gt;
        if (start &amp;gt;= 10)&lt;br /&gt;
            step *= 2;&lt;br /&gt;
        indices.push_back(i);&lt;br /&gt;
    }&lt;br /&gt;
    indices.push_back(0);&lt;br /&gt;
    return indices;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that it is allowed to send in fewer known hashes down to a minimum of just one hash. However, the purpose of the block locator object is to detect a wrong branch in the caller&#039;s main chain. If the peer detects that you are off the main chain, it will send in block hashes which are earlier than your last known block. So if you just send in your last known hash and it is off the main chain, the peer starts over at block #1.&lt;br /&gt;
&lt;br /&gt;
=== getheaders ===&lt;br /&gt;
&lt;br /&gt;
Return a &#039;&#039;headers&#039;&#039; packet containing the headers of blocks starting right after the last known hash in the block locator object, up to hash_stop or 2000 blocks, whichever comes first. To receive the next block headers, one needs to issue getheaders again with a new block locator object. The &#039;&#039;getheaders&#039;&#039; command is used by thin clients to quickly download the block chain where the contents of the transactions would be irrelevant (because they are not ours). Keep in mind that some clients may provide headers of blocks which are invalid if the block locator object contains a hash on the invalid branch.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || the protocol version&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || hash count || [[Protocol_documentation#Variable_length_integer|var_int]] || number of block locator hash entries&lt;br /&gt;
|-&lt;br /&gt;
| 32+ || block locator hashes || char[32] || block locator object; newest back to genesis block (dense to start, but then sparse)&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash_stop || char[32] || hash of the last desired block header; set to zero to get as many blocks as possible (2000)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For the block locator object in this packet, the same rules apply as for the [[Protocol_documentation#getblocks|getblocks]] packet.&lt;br /&gt;
&lt;br /&gt;
=== tx ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;tx&#039;&#039; describes a bitcoin transaction, in reply to &#039;&#039;[[#getdata|getdata]]&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || int32_t || Transaction data format version (note, this is signed)&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || tx_in count || [[Protocol_documentation#Variable_length_integer|var_int]] || Number of Transaction inputs&lt;br /&gt;
|-&lt;br /&gt;
| 41+ || tx_in || tx_in[] || A list of 1 or more transaction inputs or sources for coins&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || tx_out count || [[Protocol_documentation#Variable_length_integer|var_int]] || Number of Transaction outputs&lt;br /&gt;
|-&lt;br /&gt;
| 9+ || tx_out || tx_out[] || A list of 1 or more transaction outputs or destinations for coins&lt;br /&gt;
|-&lt;br /&gt;
| 4 || lock_time || uint32_t || The block number or timestamp at which this transaction is locked:&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0 || Not locked&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt; 500000000  || Block number at which this transaction is locked&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;= 500000000 || UNIX timestamp at which this transaction is locked&lt;br /&gt;
|}&lt;br /&gt;
If all TxIn inputs have final (0xffffffff) sequence numbers then lock_time is irrelevant. Otherwise, the transaction may not be added to a block until after lock_time (see [[NLockTime]]).&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
TxIn consists of the following fields:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 36 || previous_output || outpoint || The previous output transaction reference, as an OutPoint structure&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || script length || [[Protocol_documentation#Variable_length_integer|var_int]] || The length of the signature script&lt;br /&gt;
|-&lt;br /&gt;
| ? || signature script || uchar[] || Computational Script for confirming transaction authorization&lt;br /&gt;
|-&lt;br /&gt;
| 4 || [http://bitcoin.stackexchange.com/q/2025/323 sequence] || uint32_t || Transaction version as defined by the sender. Intended for &amp;quot;replacement&amp;quot; of transactions when information is updated before inclusion into a block.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The OutPoint structure consists of the following fields:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 32 || hash || char[32] || The hash of the referenced transaction.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || index || uint32_t || The index of the specific output in the transaction. The first output is 0, etc.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The Script structure consists of a series of pieces of information and operations related to the value of the transaction.&lt;br /&gt;
&lt;br /&gt;
(Structure to be expanded in the future… see script.h and script.cpp and [[Script]] for more information)&lt;br /&gt;
&lt;br /&gt;
The TxOut structure consists of the following fields:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 8 || value || int64_t || Transaction Value&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || pk_script length || [[Protocol_documentation#Variable_length_integer|var_int]] || Length of the pk_script&lt;br /&gt;
|-&lt;br /&gt;
| ? || pk_script || uchar[] || Usually contains the public key as a Bitcoin script setting up conditions to claim this output.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example &#039;&#039;tx&#039;&#039; message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
000000	F9 BE B4 D9 74 78 00 00  00 00 00 00 00 00 00 00   ....tx..........&lt;br /&gt;
000010	02 01 00 00 E2 93 CD BE  01 00 00 00 01 6D BD DB   .............m..&lt;br /&gt;
000020	08 5B 1D 8A F7 51 84 F0  BC 01 FA D5 8D 12 66 E9   .[...Q........f.&lt;br /&gt;
000030	B6 3B 50 88 19 90 E4 B4  0D 6A EE 36 29 00 00 00   .;P......j.6)...&lt;br /&gt;
000040	00 8B 48 30 45 02 21 00  F3 58 1E 19 72 AE 8A C7   ..H0E.!..X..r...&lt;br /&gt;
000050	C7 36 7A 7A 25 3B C1 13  52 23 AD B9 A4 68 BB 3A   .6zz%;..R#...h.:&lt;br /&gt;
000060	59 23 3F 45 BC 57 83 80  02 20 59 AF 01 CA 17 D0   Y#?E.W... Y.....&lt;br /&gt;
000070	0E 41 83 7A 1D 58 E9 7A  A3 1B AE 58 4E DE C2 8D   .A.z.X.z...XN...&lt;br /&gt;
000080	35 BD 96 92 36 90 91 3B  AE 9A 01 41 04 9C 02 BF   5...6..;...A....&lt;br /&gt;
000090	C9 7E F2 36 CE 6D 8F E5  D9 40 13 C7 21 E9 15 98   .~.6.m...@..!...&lt;br /&gt;
0000A0	2A CD 2B 12 B6 5D 9B 7D  59 E2 0A 84 20 05 F8 FC   *.+..].}Y... ...&lt;br /&gt;
0000B0	4E 02 53 2E 87 3D 37 B9  6F 09 D6 D4 51 1A DA 8F   N.S..=7.o...Q...&lt;br /&gt;
0000C0	14 04 2F 46 61 4A 4C 70  C0 F1 4B EF F5 FF FF FF   ../FaJLp..K.....&lt;br /&gt;
0000D0	FF 02 40 4B 4C 00 00 00  00 00 19 76 A9 14 1A A0   ..@KL......v....&lt;br /&gt;
0000E0	CD 1C BE A6 E7 45 8A 7A  BA D5 12 A9 D9 EA 1A FB   .....E.z........&lt;br /&gt;
0000F0	22 5E 88 AC 80 FA E9 C7  00 00 00 00 19 76 A9 14   &amp;quot;^...........v..&lt;br /&gt;
000100	0E AB 5B EA 43 6A 04 84  CF AB 12 48 5E FD A0 B7   ..[.Cj.....H^...&lt;br /&gt;
000110	8B 4E CC 52 88 AC 00 00  00 00                     .N.R......&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Message header:&lt;br /&gt;
 F9 BE B4 D9                                       - main network magic bytes&lt;br /&gt;
 74 78 00 00 00 00 00 00 00 00 00 00               - &amp;quot;tx&amp;quot; command&lt;br /&gt;
 02 01 00 00                                       - payload is 258 bytes long&lt;br /&gt;
 E2 93 CD BE                                       - checksum of payload&lt;br /&gt;
&lt;br /&gt;
Transaction:&lt;br /&gt;
 01 00 00 00                                       - version&lt;br /&gt;
&lt;br /&gt;
Inputs:&lt;br /&gt;
 01                                                - number of transaction inputs&lt;br /&gt;
&lt;br /&gt;
Input 1:&lt;br /&gt;
 6D BD DB 08 5B 1D 8A F7  51 84 F0 BC 01 FA D5 8D  - previous output (outpoint)&lt;br /&gt;
 12 66 E9 B6 3B 50 88 19  90 E4 B4 0D 6A EE 36 29&lt;br /&gt;
 00 00 00 00&lt;br /&gt;
&lt;br /&gt;
 8B                                                - script is 139 bytes long&lt;br /&gt;
&lt;br /&gt;
 48 30 45 02 21 00 F3 58  1E 19 72 AE 8A C7 C7 36  - signature script (scriptSig)&lt;br /&gt;
 7A 7A 25 3B C1 13 52 23  AD B9 A4 68 BB 3A 59 23&lt;br /&gt;
 3F 45 BC 57 83 80 02 20  59 AF 01 CA 17 D0 0E 41&lt;br /&gt;
 83 7A 1D 58 E9 7A A3 1B  AE 58 4E DE C2 8D 35 BD&lt;br /&gt;
 96 92 36 90 91 3B AE 9A  01 41 04 9C 02 BF C9 7E&lt;br /&gt;
 F2 36 CE 6D 8F E5 D9 40  13 C7 21 E9 15 98 2A CD&lt;br /&gt;
 2B 12 B6 5D 9B 7D 59 E2  0A 84 20 05 F8 FC 4E 02&lt;br /&gt;
 53 2E 87 3D 37 B9 6F 09  D6 D4 51 1A DA 8F 14 04&lt;br /&gt;
 2F 46 61 4A 4C 70 C0 F1  4B EF F5&lt;br /&gt;
&lt;br /&gt;
 FF FF FF FF                                       - sequence&lt;br /&gt;
&lt;br /&gt;
Outputs:&lt;br /&gt;
 02                                                - 2 Output Transactions&lt;br /&gt;
&lt;br /&gt;
Output 1:&lt;br /&gt;
 40 4B 4C 00 00 00 00 00                           - 0.05 BTC (5000000)&lt;br /&gt;
 19                                                - pk_script is 25 bytes long&lt;br /&gt;
&lt;br /&gt;
 76 A9 14 1A A0 CD 1C BE  A6 E7 45 8A 7A BA D5 12  - pk_script&lt;br /&gt;
 A9 D9 EA 1A FB 22 5E 88  AC&lt;br /&gt;
&lt;br /&gt;
Output 2:&lt;br /&gt;
 80 FA E9 C7 00 00 00 00                           - 33.54 BTC (3354000000)&lt;br /&gt;
 19                                                - pk_script is 25 bytes long&lt;br /&gt;
&lt;br /&gt;
 76 A9 14 0E AB 5B EA 43  6A 04 84 CF AB 12 48 5E  - pk_script&lt;br /&gt;
 FD A0 B7 8B 4E CC 52 88  AC&lt;br /&gt;
&lt;br /&gt;
Locktime:&lt;br /&gt;
 00 00 00 00                                       - lock time&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== block ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;block&#039;&#039;&#039; message is sent in response to a getdata message which requests transaction information from a block hash.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || int32_t || Block version information (note, this is signed)&lt;br /&gt;
|-&lt;br /&gt;
| 32 || prev_block || char[32] || The hash value of the previous block this particular block references&lt;br /&gt;
|-&lt;br /&gt;
| 32 || merkle_root || char[32] || The reference to a Merkle tree collection which is a hash of all transactions related to this block&lt;br /&gt;
|-&lt;br /&gt;
| 4 || timestamp || uint32_t || A Unix timestamp recording when this block was created (Currently limited to dates before the year 2106!)&lt;br /&gt;
|-&lt;br /&gt;
| 4 || bits || uint32_t || The calculated [[Difficulty|difficulty target]] being used for this block&lt;br /&gt;
|-&lt;br /&gt;
| 4 || nonce || uint32_t || The nonce used to generate this block… to allow variations of the header and compute different hashes&lt;br /&gt;
|-&lt;br /&gt;
| ? || txn_count || [[Protocol_documentation#Variable_length_integer|var_int]] || Number of transaction entries&lt;br /&gt;
|-&lt;br /&gt;
| ? || txns || tx[] || Block transactions, in format of &amp;quot;tx&amp;quot; command&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The SHA256 hash that identifies each block (and which must have a run of 0 bits) is calculated from the first 6 fields of this structure (version, prev_block, merkle_root, timestamp, bits, nonce, and standard SHA256 padding, making two 64-byte chunks in all) and &#039;&#039;not&#039;&#039; from the complete block. To calculate the hash, only two chunks need to be processed by the SHA256 algorithm. Since the &#039;&#039;nonce&#039;&#039; field is in the second chunk, the first chunk stays constant during mining and therefore only the second chunk needs to be processed. However, a Bitcoin hash is the hash of the hash, so two SHA256 rounds are needed for each mining iteration.&lt;br /&gt;
See [[Block hashing algorithm]] for details and an example.&lt;br /&gt;
&lt;br /&gt;
=== headers ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;headers&#039;&#039; packet returns block headers in response to a &#039;&#039;getheaders&#039;&#039; packet. &lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || count || [[Protocol_documentation#Variable_length_integer|var_int]] || Number of block headers&lt;br /&gt;
|-&lt;br /&gt;
| 81x? || headers || [[Protocol_documentation#Block_Headers|block_header]][] || [[Protocol_documentation#Block_Headers|Block headers]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that the block headers in this packet include a transaction count (a var_int, so there can be more than 81 bytes per header) as opposed to the block headers which are sent to miners.&lt;br /&gt;
&lt;br /&gt;
=== getaddr ===&lt;br /&gt;
&lt;br /&gt;
The getaddr message sends a request to a node asking for information about known active peers to help with finding potential nodes in the network. The response to receiving this message is to transmit one or more addr messages with one or more peers from a database of known active peers. The typical presumption is that a node is likely to be active if it has been sending a message within the last three hours.&lt;br /&gt;
&lt;br /&gt;
No additional data is transmitted with this message.&lt;br /&gt;
&lt;br /&gt;
=== mempool ===&lt;br /&gt;
&lt;br /&gt;
The mempool message sends a request to a node asking for information about transactions it has verified but which have not yet confirmed. The response to receiving this message is an inv message containing the transaction hashes for all the transactions in the node&#039;s mempool.&lt;br /&gt;
&lt;br /&gt;
No additional data is transmitted with this message.&lt;br /&gt;
&lt;br /&gt;
It is specified in [https://github.com/bitcoin/bips/blob/master/bip-0035.mediawiki BIP 35]. Since [https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki BIP 37], if a [[Protocol_documentation#filterload.2C_filteradd.2C_filterclear.2C_merkleblock|bloom filter]] is loaded, only transactions matching the filter are replied.&lt;br /&gt;
&lt;br /&gt;
=== checkorder ===&lt;br /&gt;
&lt;br /&gt;
This message was used for [[IP Transactions]]. As IP transactions have been deprecated, it is no longer used.&lt;br /&gt;
&lt;br /&gt;
=== submitorder ===&lt;br /&gt;
&lt;br /&gt;
This message was used for [[IP Transactions]]. As IP transactions have been deprecated, it is no longer used.&lt;br /&gt;
&lt;br /&gt;
=== reply ===&lt;br /&gt;
&lt;br /&gt;
This message was used for [[IP Transactions]]. As IP transactions have been deprecated, it is no longer used.&lt;br /&gt;
&lt;br /&gt;
=== ping ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;ping&#039;&#039; message is sent primarily to confirm that the TCP/IP connection is still valid. An error in transmission is presumed to be a closed connection and the address is removed as a current peer.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 8 || nonce || uint64_t || random nonce&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== pong ===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;pong&#039;&#039; message is sent in response to a &#039;&#039;ping&#039;&#039; message. In modern protocol versions, a &#039;&#039;pong&#039;&#039; response is generated using a nonce included in the ping.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 8 || nonce || uint64_t || nonce from ping&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== reject===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;reject&#039;&#039; message is sent when messages are rejected.&lt;br /&gt;
&lt;br /&gt;
Payload:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || message || var_str || type of message rejected&lt;br /&gt;
|-&lt;br /&gt;
| 1 || ccode || char || code relating to rejected message&lt;br /&gt;
|-&lt;br /&gt;
| 1+ || reason || var_str || text version of reason for rejection&lt;br /&gt;
|-&lt;br /&gt;
| 0+ || data || char || Optional extra data provided by some errors.  Currently, all errors which provide this field fill it with the TXID or block header hash of the object being rejected, so the field is 32 bytes.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
CCodes&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Value !! Name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| 0x01 || REJECT_MALFORMED|| &lt;br /&gt;
|-&lt;br /&gt;
| 0x10 || REJECT_INVALID ||&lt;br /&gt;
|-&lt;br /&gt;
| 0x11 || REJECT_OBSOLETE ||&lt;br /&gt;
|-&lt;br /&gt;
| 0x12 || REJECT_DUPLICATE ||&lt;br /&gt;
|-&lt;br /&gt;
| 0x40 || REJECT_NONSTANDARD ||&lt;br /&gt;
|-&lt;br /&gt;
| 0x41 || REJECT_DUST ||&lt;br /&gt;
|-&lt;br /&gt;
| 0x42 || REJECT_INSUFFICIENTFEE ||&lt;br /&gt;
|-&lt;br /&gt;
| 0x43 || REJECT_CHECKPOINT ||&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== filterload, filteradd, filterclear, merkleblock ===&lt;br /&gt;
&lt;br /&gt;
These messages are related to Bloom filtering of connections and are defined in [https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki BIP 0037].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;filterload&amp;lt;/code&amp;gt; command is defined as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || filter || uint8_t[] || The filter itself is simply a bit field of arbitrary byte-aligned size. The maximum size is 36,000 bytes.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || nHashFuncs || uint32_t || The number of hash functions to use in this filter. The maximum value allowed in this field is 50.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || nTweak || uint32_t || A random value to add to the seed value in the hash function used by the bloom filter.&lt;br /&gt;
|-&lt;br /&gt;
| 1 || nFlags || uint8_t || A set of flags that control how matched items are added to the filter.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
See below for a description of the Bloom filter algorithm and how to select nHashFuncs and filter size for a desired false positive rate.&lt;br /&gt;
&lt;br /&gt;
Upon receiving a &amp;lt;code&amp;gt;filterload&amp;lt;/code&amp;gt; command, the remote peer will immediately restrict the broadcast transactions it announces (in inv packets) to transactions matching the filter, where the matching algorithm is specified below. The flags control the update behaviour of the matching algorithm.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;filteradd&amp;lt;/code&amp;gt; command is defined as follows:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || data || uint8_t[] || The data element to add to the current filter.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The data field must be smaller than or equal to 520 bytes in size (the maximum size of any potentially matched object).&lt;br /&gt;
&lt;br /&gt;
The given data element will be added to the Bloom filter. A filter must have been previously provided using &amp;lt;code&amp;gt;filterload&amp;lt;/code&amp;gt;. This command is useful if a new key or script is added to a clients wallet whilst it has connections to the network open, it avoids the need to re-calculate and send an entirely new filter to every peer (though doing so is usually advisable to maintain anonymity).&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;filterclear&amp;lt;/code&amp;gt; command has no arguments at all.&lt;br /&gt;
&lt;br /&gt;
After a filter has been set, nodes don&#039;t merely stop announcing non-matching transactions, they can also serve filtered blocks. A filtered block is defined by the &amp;lt;code&amp;gt;merkleblock&amp;lt;/code&amp;gt; message and is defined like this:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || version || uint32_t || Block version information, based upon the software version creating this block&lt;br /&gt;
|-&lt;br /&gt;
| 32 || prev_block || char[32] || The hash value of the previous block this particular block references&lt;br /&gt;
|-&lt;br /&gt;
| 32 || merkle_root || char[32] || The reference to a Merkle tree collection which is a hash of all transactions related to this block&lt;br /&gt;
|-&lt;br /&gt;
| 4 || timestamp || uint32_t || A timestamp recording when this block was created (Limited to 2106!)&lt;br /&gt;
|-&lt;br /&gt;
| 4 || bits || uint32_t || The calculated difficulty target being used for this block&lt;br /&gt;
|-&lt;br /&gt;
| 4 || nonce || uint32_t || The nonce used to generate this block… to allow variations of the header and compute different hashes&lt;br /&gt;
|-&lt;br /&gt;
| 4 || total_transactions || uint32_t || Number of transactions in the block (including unmatched ones)&lt;br /&gt;
|-&lt;br /&gt;
| ? || hashes || uint256[] || hashes in depth-first order (including standard varint size prefix)&lt;br /&gt;
|-&lt;br /&gt;
| ? || flags || byte[] || flag bits, packed per 8 in a byte, least significant bit first (including standard varint size prefix)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== alert ===&lt;br /&gt;
&lt;br /&gt;
An &#039;&#039;&#039;alert&#039;&#039;&#039; is sent between nodes to send a general notification message throughout the network. If the alert can be confirmed with the signature as having come from the core development group of the Bitcoin software, the message is suggested to be displayed for end-users. Attempts to perform transactions, particularly automated transactions through the client, are suggested to be halted. The text in the Message string should be relayed to log files and any user interfaces.&lt;br /&gt;
&lt;br /&gt;
Alert format:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| ? || payload || uchar[] || Serialized alert payload&lt;br /&gt;
|-&lt;br /&gt;
| ? || signature || uchar[] || An ECDSA signature of the message&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The developers of Satoshi&#039;s client use this public key for signing alerts:&lt;br /&gt;
 04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284&lt;br /&gt;
 (hash) 1AGRxqDa5WjUKBwHB9XYEjmkv1ucoUUy1s&lt;br /&gt;
&lt;br /&gt;
The payload is serialized into a uchar[] to ensure that versions using incompatible alert formats can still relay alerts among one another. The current alert payload format is:&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field Size !! Description !! Data type !! Comments&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Version || int32_t || Alert format version&lt;br /&gt;
|-&lt;br /&gt;
| 8 || RelayUntil || int64_t || The timestamp beyond which nodes should stop relaying this alert&lt;br /&gt;
|-&lt;br /&gt;
| 8 || Expiration || int64_t || The timestamp beyond which this alert is no longer in effect and should be ignored&lt;br /&gt;
|-&lt;br /&gt;
| 4 || ID || int32_t || A unique ID number for this alert&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Cancel || int32_t || All alerts with an ID number less than or equal to this number should be cancelled: deleted and not accepted in the future&lt;br /&gt;
|-&lt;br /&gt;
| ? || setCancel || set&amp;lt;int32_t&amp;gt; || All alert IDs contained in this set should be cancelled as above&lt;br /&gt;
|-&lt;br /&gt;
| 4 || MinVer || int32_t || This alert only applies to versions greater than or equal to this version. Other versions should still relay it.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || MaxVer || int32_t || This alert only applies to versions less than or equal to this version. Other versions should still relay it.&lt;br /&gt;
|-&lt;br /&gt;
| ? || setSubVer || set&amp;lt;string&amp;gt; || If this set contains any elements, then only nodes that have their subVer contained in this set are affected by the alert. Other versions should still relay it.&lt;br /&gt;
|-&lt;br /&gt;
| 4 || Priority || int32_t || Relative priority compared to other alerts&lt;br /&gt;
|-&lt;br /&gt;
| ? || Comment || string || A comment on the alert that is not displayed&lt;br /&gt;
|-&lt;br /&gt;
| ? || StatusBar || string || The alert message that is displayed to the user&lt;br /&gt;
|-&lt;br /&gt;
| ? || Reserved || string || Reserved&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note: &#039;&#039;&#039;set&amp;lt;&#039;&#039;type&#039;&#039;&amp;gt;&#039;&#039;&#039; in the table above is a [[#Variable length integer | variable length integer]] followed by the number of fields of the given &#039;&#039;type&#039;&#039; (either int32_t or [[#Variable length string | variable length string]])&lt;br /&gt;
&lt;br /&gt;
Sample alert (no message header):&lt;br /&gt;
 73010000003766404f00000000b305434f00000000f2030000f1030000001027000048ee0000&lt;br /&gt;
 0064000000004653656520626974636f696e2e6f72672f666562323020696620796f75206861&lt;br /&gt;
 76652074726f75626c6520636f6e6e656374696e672061667465722032302046656272756172&lt;br /&gt;
 79004730450221008389df45f0703f39ec8c1cc42c13810ffcae14995bb648340219e353b63b&lt;br /&gt;
 53eb022009ec65e1c1aaeec1fd334c6b684bde2b3f573060d5b70c3a46723326e4e8a4f1&lt;br /&gt;
 &lt;br /&gt;
 Version: 1&lt;br /&gt;
 RelayUntil: 1329620535&lt;br /&gt;
 Expiration: 1329792435&lt;br /&gt;
 ID: 1010&lt;br /&gt;
 Cancel: 1009&lt;br /&gt;
 setCancel: &amp;lt;empty&amp;gt;&lt;br /&gt;
 MinVer: 10000&lt;br /&gt;
 MaxVer: 61000&lt;br /&gt;
 setSubVer: &amp;lt;empty&amp;gt;&lt;br /&gt;
 Priority: 100&lt;br /&gt;
 Comment: &amp;lt;empty&amp;gt;&lt;br /&gt;
 StatusBar: &amp;quot;See bitcoin.org/feb20 if you have trouble connecting after 20 February&amp;quot;&lt;br /&gt;
 Reserved: &amp;lt;empty&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Scripting ==&lt;br /&gt;
&lt;br /&gt;
See [[script]].&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
&lt;br /&gt;
* [[Network]]&lt;br /&gt;
* [[Protocol rules]]&lt;br /&gt;
* [[Hardfork Wishlist]]&lt;br /&gt;
* [https://bitcoin.org/en/developer-documentation Developer Documentation on bitcoin.org]&lt;br /&gt;
* Bitcoin dissectors for Wireshark: https://github.com/lbotsch/wireshark-bitcoin https://github.com/op-sig/bitcoin-wireshark-dissector&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[zh-cn:协议说明]]&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
&lt;br /&gt;
{{Bitcoin Core documentation}}&lt;/div&gt;</summary>
		<author><name>Tkerin</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Transaction&amp;diff=47506</id>
		<title>Transaction</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Transaction&amp;diff=47506"/>
		<updated>2014-05-21T12:41:17Z</updated>

		<summary type="html">&lt;p&gt;Tkerin: /* Pay-to-Script-Hash */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:TxBinaryMap.png|thumb|right|Byte-map of Transaction with each type of TxIn and TxOut]]&lt;br /&gt;
A &#039;&#039;&#039;transaction&#039;&#039;&#039; is a signed section of data that is broadcast to the [[network]] and collected into [[block|blocks]]. It typically references previous transaction(s) and dedicates a certain number of bitcoins from it to one or more new public key(s) (Bitcoin address). It is not encrypted (nothing in Bitcoin is encrypted).&lt;br /&gt;
&lt;br /&gt;
A [[block chain browser]] is a site where every transaction included within the block chain can be viewed.  This is useful for seeing the technical details of transaction in action, and for payment verification purposes.&lt;br /&gt;
&lt;br /&gt;
=== general format of a Bitcoin transaction (inside a block) ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Description&lt;br /&gt;
! Size&lt;br /&gt;
|-&lt;br /&gt;
|Version no&lt;br /&gt;
|currently 1&lt;br /&gt;
|4 bytes&lt;br /&gt;
|-&lt;br /&gt;
|In-counter&lt;br /&gt;
| positive integer [[ Protocol_specification#Variable_length_integer|VI = VarInt]]&lt;br /&gt;
| 1 - 9 bytes &lt;br /&gt;
|-&lt;br /&gt;
|list of inputs&lt;br /&gt;
|[[Transactions#general_format_.28inside_a_block.29_of_each_input_of_a_transaction_-_Txin|the first input of the first transaction is also called &amp;quot;coinbase&amp;quot; (its content was ignored in earlier versions)]]&lt;br /&gt;
|&amp;lt;in-counter&amp;gt;-many inputs&lt;br /&gt;
|-&lt;br /&gt;
|Out-counter&lt;br /&gt;
| positive integer [[ Protocol_specification#Variable_length_integer|VI = VarInt]]&lt;br /&gt;
| 1 - 9 bytes&lt;br /&gt;
|-&lt;br /&gt;
|list of outputs&lt;br /&gt;
|[[Transactions#general_format_.28inside_a_block.29_of_each_output_of_a_transaction_-_Txout|the outputs of the first transaction spend the mined bitcoins for the block]]&lt;br /&gt;
|&amp;lt;out-counter&amp;gt;-many outputs&lt;br /&gt;
|-&lt;br /&gt;
|lock_time&lt;br /&gt;
|if non-zero and sequence numbers are &amp;lt; 0xFFFFFFFF: block height or timestamp when transaction is final&lt;br /&gt;
|4 bytes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Principle example of a Bitcoin transaction with 1 input and 1 output only ===&lt;br /&gt;
&lt;br /&gt;
==== Data ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Input:&lt;br /&gt;
Previous tx: f5d8ee39a430901c91a5917b9f2dc19d6d1a0e9cea205b009ca73dd04470b9a6&lt;br /&gt;
Index: 0&lt;br /&gt;
scriptSig: 304502206e21798a42fae0e854281abd38bacd1aeed3ee3738d9e1446618c4571d10&lt;br /&gt;
90db022100e2ac980643b0b82c0e88ffdfec6b64e3e6ba35e7ba5fdd7d5d6cc8d25c6b241501&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
Value: 5000000000&lt;br /&gt;
scriptPubKey: OP_DUP OP_HASH160 404371705fa9bd789a2fcd52d2c580b65d35549d&lt;br /&gt;
OP_EQUALVERIFY OP_CHECKSIG&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Explanation ====&lt;br /&gt;
&lt;br /&gt;
The input in this transaction imports 50 BTC from output #0 in transaction f5d8... Then the output sends 50 BTC to a Bitcoin address (expressed here in hexadecimal 4043... instead of the normal base58). When the recipient wants to spend this money, he will reference output #0 of this transaction in an input of his own transaction.&lt;br /&gt;
&lt;br /&gt;
===== Input =====&lt;br /&gt;
&lt;br /&gt;
An &#039;&#039;&#039;input&#039;&#039;&#039; is a reference to an output in a different transaction. Multiple inputs are often listed in a transaction. The values of the referenced outputs are added up, and the total is usable in the outputs of this transaction. &#039;&#039;&#039;Previous tx&#039;&#039;&#039; is a [[hash]] of a previous transaction. &#039;&#039;&#039;Index&#039;&#039;&#039; is the specific output in the referenced transaction. &#039;&#039;&#039;ScriptSig&#039;&#039;&#039; is the first half of a [[script]] (discussed in more detail later).&lt;br /&gt;
&lt;br /&gt;
The script contains two components, a signature and a public key. The public key belongs to the redeemer of the output transaction and proves the creator is allowed to redeem the outputs value. The other component is an ECDSA signature over a hash of a simplified version of the transaction. It, combined with the public key, proves the transaction was created by the real owner of the address in question. Various flags define how the transaction is simplified and can be used to create different types of payment.&lt;br /&gt;
&lt;br /&gt;
===== Output =====&lt;br /&gt;
&lt;br /&gt;
An &#039;&#039;&#039;output&#039;&#039;&#039; contains instructions for sending bitcoins. &#039;&#039;&#039;Value&#039;&#039;&#039; is the number of Satoshi (1 BTC = 100,000,000 Satoshi) that this output will be worth when claimed. &#039;&#039;&#039;ScriptPubKey&#039;&#039;&#039; is the second half of a script (discussed later). There can be more than one output, and they share the combined value of the inputs. Because each output from one transaction can only ever be referenced once by an input of a subsequent transaction, the entire combined input value needs to be sent in an output if you don&#039;t want to lose it. If the input is worth 50 BTC but you only want to send 25 BTC, Bitcoin will create two outputs worth 25 BTC: one to the destination, and one back to you (known as &amp;quot;[[change]]&amp;quot;, though you send it to yourself). Any input bitcoins not redeemed in an output is considered a [[transaction fee]]; whoever generates the block will get it.&lt;br /&gt;
[[File:transaction.png|thumb|A sends 100 BTC to C and C generates 50 BTC. C sends 101 BTC to D, and he needs to send himself some change. D sends the 101 BTC to someone else, but they haven&#039;t redeemed it yet. Only D&#039;s output and C&#039;s change are capable of being spent in the current state.]]&lt;br /&gt;
&lt;br /&gt;
===== Verification =====&lt;br /&gt;
&lt;br /&gt;
To verify that inputs are authorized to collect the values of referenced outputs, Bitcoin uses a custom Forth-like [[script|scripting]] system. The input&#039;s scriptSig and the &#039;&#039;referenced&#039;&#039; output&#039;s scriptPubKey are evaluated (in that order), with scriptPubKey using the values left on the stack by scriptSig. The input is authorized if scriptPubKey returns true. Through the scripting system, the sender can create very complex conditions that people have to meet in order to claim the output&#039;s value. For example, it&#039;s possible to create an output that can be claimed by anyone without any authorization. It&#039;s also possible to require that an input be signed by ten different keys, or be redeemable with a password instead of a key.&lt;br /&gt;
&lt;br /&gt;
=== Types of Transaction ===&lt;br /&gt;
Bitcoin currently creates two different scriptSig/scriptPubKey pairs. These are described below.&lt;br /&gt;
&lt;br /&gt;
It is possible to design more complex types of transactions, and link them together into cryptographically enforced agreements. These are known as [[Contracts]].&lt;br /&gt;
&lt;br /&gt;
==== Pay-to-PubkeyHash ====&lt;br /&gt;
&lt;br /&gt;
 scriptPubKey: OP_DUP OP_HASH160 &amp;lt;pubKeyHash&amp;gt; OP_EQUALVERIFY OP_CHECKSIG&lt;br /&gt;
 scriptSig: &amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt;&lt;br /&gt;
A Bitcoin [[address]] is only a hash, so the sender can&#039;t provide a full public key in scriptPubKey. When redeeming coins that have been sent to a Bitcoin address, the recipient provides both the signature and the public key. The script verifies that the provided public key does hash to the hash in scriptPubKey, and then it also checks the signature against the public key.&lt;br /&gt;
&lt;br /&gt;
Checking process:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
! Stack &lt;br /&gt;
! Script &lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
|Empty.&lt;br /&gt;
| &amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt; OP_DUP OP_HASH160 &amp;lt;pubKeyHash&amp;gt; OP_EQUALVERIFY OP_CHECKSIG &lt;br /&gt;
| scriptSig and scriptPubKey are combined.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt;&lt;br /&gt;
| OP_DUP OP_HASH160 &amp;lt;pubKeyHash&amp;gt; OP_EQUALVERIFY OP_CHECKSIG &lt;br /&gt;
| Constants are added to the stack.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt; &amp;lt;pubKey&amp;gt;&lt;br /&gt;
| OP_HASH160 &amp;lt;pubKeyHash&amp;gt; OP_EQUALVERIFY OP_CHECKSIG &lt;br /&gt;
| Top stack item is duplicated.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt; &amp;lt;pubHashA&amp;gt;&lt;br /&gt;
|&amp;lt;pubKeyHash&amp;gt; OP_EQUALVERIFY OP_CHECKSIG&lt;br /&gt;
| Top stack item is hashed.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt; &amp;lt;pubHashA&amp;gt; &amp;lt;pubKeyHash&amp;gt;&lt;br /&gt;
|OP_EQUALVERIFY OP_CHECKSIG&lt;br /&gt;
| Constant added.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt;&lt;br /&gt;
|OP_CHECKSIG&lt;br /&gt;
| Equality is checked between the top two stack items.&lt;br /&gt;
|-&lt;br /&gt;
|true&lt;br /&gt;
|Empty.&lt;br /&gt;
|Signature is checked for top two stack items.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Pay-to-Script-Hash ====&lt;br /&gt;
&lt;br /&gt;
 scriptPubKey: OP_HASH160 &amp;lt;scriptHash&amp;gt; OP_EQUAL &lt;br /&gt;
 scriptSig: ..signatures... &amp;lt;serialized script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 m-of-n multi-signature transaction:&lt;br /&gt;
 scriptSig: 0 &amp;lt;sig1&amp;gt; ... &amp;lt;script&amp;gt;&lt;br /&gt;
 script: OP_m &amp;lt;pubKey1&amp;gt; ... OP_n OP_CHECKMULTISIG&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
P2SH addresses were created with the motivation of moving &amp;quot;the responsibility for supplying the conditions to redeem a transaction from the sender of the funds to the redeemer. They allow the sender to fund an arbitrary transaction, no matter how complicated, using a 20-byte hash&amp;quot;[https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki#motivation 1]. Pay-to-Pubkey-hash addresses are similarly a 20-byte hash of the public key. &lt;br /&gt;
&lt;br /&gt;
Pay-to-script-hash provides a means for complicated transactions, unlike the Pay-to-pubkey-hash, which has a specific definition for scriptPubKey, and scriptSig. The specification places no limitations on the script, and hence absolutely any contract can be funded using these addresses. &lt;br /&gt;
&lt;br /&gt;
The scriptPubKey in the funding transaction is script which ensures that the script supplied in the redeeming transaction hashes to the script used to create the address. &lt;br /&gt;
&lt;br /&gt;
In the scriptSig above, &#039;signatures&#039; refers to any script which is sufficient to satisfy the following serialized script. &lt;br /&gt;
&lt;br /&gt;
Checking process:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
! Stack &lt;br /&gt;
! Script &lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
|Empty.&lt;br /&gt;
| 0 &amp;lt;sig1&amp;gt; &amp;lt;sig2&amp;gt; OP_2 &amp;lt;pubKey1&amp;gt; &amp;lt;pubKey2&amp;gt; &amp;lt;pubKey3&amp;gt; OP_3 OP_CHECKMULTISIG &lt;br /&gt;
| Only the scriptSig is used.&lt;br /&gt;
|-&lt;br /&gt;
| 0 &amp;lt;sig1&amp;gt; &amp;lt;sig2&amp;gt; OP_2 &amp;lt;pubKey1&amp;gt; &amp;lt;pubKey2&amp;gt; &amp;lt;pubKey3&amp;gt; OP_3 &lt;br /&gt;
| OP_CHECKMULTISIG &lt;br /&gt;
| Constants are added to the stack.&lt;br /&gt;
|-&lt;br /&gt;
| true&lt;br /&gt;
| Empty&lt;br /&gt;
| Signatures validated in the order of the keys in the script.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
See also [[BIP 0016]]&lt;br /&gt;
&lt;br /&gt;
==== Generation ====&lt;br /&gt;
&lt;br /&gt;
Generations have a single input, and this input has a &amp;quot;coinbase&amp;quot; parameter instead of a scriptSig. The data in &amp;quot;coinbase&amp;quot; can be anything; it isn&#039;t used. Bitcoin puts the current compact-format [[target]] and the arbitrary-precision &amp;quot;extraNonce&amp;quot; number there, which increments every time the Nonce field in the [[block_hashing_algorithm|block header]] overflows. Outputs can be anything, but Bitcoin creates one exactly like an IP address transaction.&lt;br /&gt;
The extranonce contributes to enlarge the domain for the proof of work function. Miners can easily modify nonce (4byte), timestamp and extranonce (2 to 100bytes).&lt;br /&gt;
&lt;br /&gt;
=== general format (inside a block) of each input of a transaction - Txin ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Description&lt;br /&gt;
! Size&lt;br /&gt;
|-&lt;br /&gt;
|Previous Transaction hash &lt;br /&gt;
| doubled [[Wikipedia:SHA-256|SHA256]]-[[hash|hashed]] of a (previous) to-be-used transaction&lt;br /&gt;
|32 bytes&lt;br /&gt;
|-&lt;br /&gt;
|Previous Txout-index&lt;br /&gt;
| non negative integer indexing an output of the to-be-used transaction&lt;br /&gt;
|4 bytes&lt;br /&gt;
|-&lt;br /&gt;
|Txin-script length&lt;br /&gt;
|non negative integer [[ Protocol_specification#Variable_length_integer|VI = VarInt]]&lt;br /&gt;
|1 - 9 bytes&lt;br /&gt;
|-&lt;br /&gt;
|Txin-script / scriptSig&lt;br /&gt;
|[[Script]]&lt;br /&gt;
|&amp;lt;in-script length&amp;gt;-many bytes&lt;br /&gt;
|-&lt;br /&gt;
|sequence_no&lt;br /&gt;
|normally 0xFFFFFFFF; irrelevant unless transaction&#039;s lock_time is &amp;gt; 0&lt;br /&gt;
|4 bytes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The input sufficiently describes where and how to get the bitcoin amout to be redeemed.&lt;br /&gt;
If it is the (only) input of the first transaction of a block, it is called the generation transaction input and its content completely ignored. (Historically the Previous Transaction hash is 0 and the Previous Txout-index is -1.)&lt;br /&gt;
&lt;br /&gt;
=== general format (inside a block) of each output of a transaction - Txout ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Description&lt;br /&gt;
! Size&lt;br /&gt;
|-&lt;br /&gt;
|value&lt;br /&gt;
|non negative integer giving the number of [[FAQ#What_do_I_call_the_various_denominations_of_bitcoins.3F|Satoshis(BTC/10^8)]] to be transfered&lt;br /&gt;
|8 bytes&lt;br /&gt;
|-&lt;br /&gt;
|Txout-script length&lt;br /&gt;
|non negative integer&lt;br /&gt;
|1 - 9 bytes [[ Protocol_specification#Variable_length_integer|VI = VarInt]]&lt;br /&gt;
|-&lt;br /&gt;
|Txout-script / scriptPubKey&lt;br /&gt;
|[[Script]]&lt;br /&gt;
|&amp;lt;out-script length&amp;gt;-many bytes&lt;br /&gt;
|}&lt;br /&gt;
The output sets the conditions to release this bitcoin amount later. The sum of the output values of the first transaction is the value of the mined bitcoins for the block plus possible transactions fees of the other transactions in the block.&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
&lt;br /&gt;
* [[Script]]&lt;br /&gt;
* [[BTC Sender]] Transmit raw, hand-crafted transactions&lt;br /&gt;
* [[Raw Transactions]]&lt;br /&gt;
* [[Transaction Malleability]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;br /&gt;
[[de:Transaktion]]&lt;br /&gt;
[[es:Transacción]]&lt;br /&gt;
[[pl:Transakcje]]&lt;/div&gt;</summary>
		<author><name>Tkerin</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Transaction&amp;diff=47017</id>
		<title>Transaction</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Transaction&amp;diff=47017"/>
		<updated>2014-05-05T23:54:46Z</updated>

		<summary type="html">&lt;p&gt;Tkerin: /* Pay-to-ScriptHash */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:TxBinaryMap.png|thumb|right|Byte-map of Transaction with each type of TxIn and TxOut]]&lt;br /&gt;
A &#039;&#039;&#039;transaction&#039;&#039;&#039; is a signed section of data that is broadcast to the [[network]] and collected into [[block|blocks]]. It typically references previous transaction(s) and dedicates a certain number of bitcoins from it to one or more new public key(s) (Bitcoin address). It is not encrypted (nothing in Bitcoin is encrypted).&lt;br /&gt;
&lt;br /&gt;
A [[block chain browser]] is a site where every transaction included within the block chain can be viewed.  This is useful for seeing the technical details of transaction in action, and for payment verification purposes.&lt;br /&gt;
&lt;br /&gt;
=== general format of a Bitcoin transaction (inside a block) ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Description&lt;br /&gt;
! Size&lt;br /&gt;
|-&lt;br /&gt;
|Version no&lt;br /&gt;
|currently 1&lt;br /&gt;
|4 bytes&lt;br /&gt;
|-&lt;br /&gt;
|In-counter&lt;br /&gt;
| positive integer [[ Protocol_specification#Variable_length_integer|VI = VarInt]]&lt;br /&gt;
| 1 - 9 bytes &lt;br /&gt;
|-&lt;br /&gt;
|list of inputs&lt;br /&gt;
|[[Transactions#general_format_.28inside_a_block.29_of_each_input_of_a_transaction_-_Txin|the first input of the first transaction is also called &amp;quot;coinbase&amp;quot; (its content was ignored in earlier versions)]]&lt;br /&gt;
|&amp;lt;in-counter&amp;gt;-many inputs&lt;br /&gt;
|-&lt;br /&gt;
|Out-counter&lt;br /&gt;
| positive integer [[ Protocol_specification#Variable_length_integer|VI = VarInt]]&lt;br /&gt;
| 1 - 9 bytes&lt;br /&gt;
|-&lt;br /&gt;
|list of outputs&lt;br /&gt;
|[[Transactions#general_format_.28inside_a_block.29_of_each_output_of_a_transaction_-_Txout|the outputs of the first transaction spend the mined bitcoins for the block]]&lt;br /&gt;
|&amp;lt;out-counter&amp;gt;-many outputs&lt;br /&gt;
|-&lt;br /&gt;
|lock_time&lt;br /&gt;
|if non-zero and sequence numbers are &amp;lt; 0xFFFFFFFF: block height or timestamp when transaction is final&lt;br /&gt;
|4 bytes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Principle example of a Bitcoin transaction with 1 input and 1 output only ===&lt;br /&gt;
&lt;br /&gt;
==== Data ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Input:&lt;br /&gt;
Previous tx: f5d8ee39a430901c91a5917b9f2dc19d6d1a0e9cea205b009ca73dd04470b9a6&lt;br /&gt;
Index: 0&lt;br /&gt;
scriptSig: 304502206e21798a42fae0e854281abd38bacd1aeed3ee3738d9e1446618c4571d10&lt;br /&gt;
90db022100e2ac980643b0b82c0e88ffdfec6b64e3e6ba35e7ba5fdd7d5d6cc8d25c6b241501&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
Value: 5000000000&lt;br /&gt;
scriptPubKey: OP_DUP OP_HASH160 404371705fa9bd789a2fcd52d2c580b65d35549d&lt;br /&gt;
OP_EQUALVERIFY OP_CHECKSIG&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Explanation ====&lt;br /&gt;
&lt;br /&gt;
The input in this transaction imports 50 BTC from output #0 in transaction f5d8... Then the output sends 50 BTC to a Bitcoin address (expressed here in hexadecimal 4043... instead of the normal base58). When the recipient wants to spend this money, he will reference output #0 of this transaction in an input of his own transaction.&lt;br /&gt;
&lt;br /&gt;
===== Input =====&lt;br /&gt;
&lt;br /&gt;
An &#039;&#039;&#039;input&#039;&#039;&#039; is a reference to an output in a different transaction. Multiple inputs are often listed in a transaction. The values of the referenced outputs are added up, and the total is usable in the outputs of this transaction. &#039;&#039;&#039;Previous tx&#039;&#039;&#039; is a [[hash]] of a previous transaction. &#039;&#039;&#039;Index&#039;&#039;&#039; is the specific output in the referenced transaction. &#039;&#039;&#039;ScriptSig&#039;&#039;&#039; is the first half of a [[script]] (discussed in more detail later).&lt;br /&gt;
&lt;br /&gt;
The script contains two components, a signature and a public key. The public key belongs to the redeemer of the output transaction and proves the creator is allowed to redeem the outputs value. The other component is an ECDSA signature over a hash of a simplified version of the transaction. It, combined with the public key, proves the transaction was created by the real owner of the address in question. Various flags define how the transaction is simplified and can be used to create different types of payment.&lt;br /&gt;
&lt;br /&gt;
===== Output =====&lt;br /&gt;
&lt;br /&gt;
An &#039;&#039;&#039;output&#039;&#039;&#039; contains instructions for sending bitcoins. &#039;&#039;&#039;Value&#039;&#039;&#039; is the number of Satoshi (1 BTC = 100,000,000 Satoshi) that this output will be worth when claimed. &#039;&#039;&#039;ScriptPubKey&#039;&#039;&#039; is the second half of a script (discussed later). There can be more than one output, and they share the combined value of the inputs. Because each output from one transaction can only ever be referenced once by an input of a subsequent transaction, the entire combined input value needs to be sent in an output if you don&#039;t want to lose it. If the input is worth 50 BTC but you only want to send 25 BTC, Bitcoin will create two outputs worth 25 BTC: one to the destination, and one back to you (known as &amp;quot;[[change]]&amp;quot;, though you send it to yourself). Any input bitcoins not redeemed in an output is considered a [[transaction fee]]; whoever generates the block will get it.&lt;br /&gt;
[[File:transaction.png|thumb|A sends 100 BTC to C and C generates 50 BTC. C sends 101 BTC to D, and he needs to send himself some change. D sends the 101 BTC to someone else, but they haven&#039;t redeemed it yet. Only D&#039;s output and C&#039;s change are capable of being spent in the current state.]]&lt;br /&gt;
&lt;br /&gt;
===== Verification =====&lt;br /&gt;
&lt;br /&gt;
To verify that inputs are authorized to collect the values of referenced outputs, Bitcoin uses a custom Forth-like [[script|scripting]] system. The input&#039;s scriptSig and the &#039;&#039;referenced&#039;&#039; output&#039;s scriptPubKey are evaluated (in that order), with scriptPubKey using the values left on the stack by scriptSig. The input is authorized if scriptPubKey returns true. Through the scripting system, the sender can create very complex conditions that people have to meet in order to claim the output&#039;s value. For example, it&#039;s possible to create an output that can be claimed by anyone without any authorization. It&#039;s also possible to require that an input be signed by ten different keys, or be redeemable with a password instead of a key.&lt;br /&gt;
&lt;br /&gt;
=== Types of Transaction ===&lt;br /&gt;
Bitcoin currently creates two different scriptSig/scriptPubKey pairs. These are described below.&lt;br /&gt;
&lt;br /&gt;
It is possible to design more complex types of transactions, and link them together into cryptographically enforced agreements. These are known as [[Contracts]].&lt;br /&gt;
&lt;br /&gt;
==== Pay-to-PubkeyHash ====&lt;br /&gt;
&lt;br /&gt;
 scriptPubKey: OP_DUP OP_HASH160 &amp;lt;pubKeyHash&amp;gt; OP_EQUALVERIFY OP_CHECKSIG&lt;br /&gt;
 scriptSig: &amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt;&lt;br /&gt;
A Bitcoin [[address]] is only a hash, so the sender can&#039;t provide a full public key in scriptPubKey. When redeeming coins that have been sent to a Bitcoin address, the recipient provides both the signature and the public key. The script verifies that the provided public key does hash to the hash in scriptPubKey, and then it also checks the signature against the public key.&lt;br /&gt;
&lt;br /&gt;
Checking process:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
! Stack &lt;br /&gt;
! Script &lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
|Empty.&lt;br /&gt;
| &amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt; OP_DUP OP_HASH160 &amp;lt;pubKeyHash&amp;gt; OP_EQUALVERIFY OP_CHECKSIG &lt;br /&gt;
| scriptSig and scriptPubKey are combined.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt;&lt;br /&gt;
| OP_DUP OP_HASH160 &amp;lt;pubKeyHash&amp;gt; OP_EQUALVERIFY OP_CHECKSIG &lt;br /&gt;
| Constants are added to the stack.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt; &amp;lt;pubKey&amp;gt;&lt;br /&gt;
| OP_HASH160 &amp;lt;pubKeyHash&amp;gt; OP_EQUALVERIFY OP_CHECKSIG &lt;br /&gt;
| Top stack item is duplicated.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt; &amp;lt;pubHashA&amp;gt;&lt;br /&gt;
|&amp;lt;pubKeyHash&amp;gt; OP_EQUALVERIFY OP_CHECKSIG&lt;br /&gt;
| Top stack item is hashed.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt; &amp;lt;pubHashA&amp;gt; &amp;lt;pubKeyHash&amp;gt;&lt;br /&gt;
|OP_EQUALVERIFY OP_CHECKSIG&lt;br /&gt;
| Constant added.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt;&lt;br /&gt;
|OP_CHECKSIG&lt;br /&gt;
| Equality is checked between the top two stack items.&lt;br /&gt;
|-&lt;br /&gt;
|true&lt;br /&gt;
|Empty.&lt;br /&gt;
|Signature is checked for top two stack items.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Pay-to-Script-Hash ====&lt;br /&gt;
&lt;br /&gt;
 scriptPubKey: OP_HASH160 &amp;lt;scriptHash&amp;gt; OP_EQUAL &lt;br /&gt;
 scriptSig: ..signatures... &amp;lt;serialized script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 m-of-n multi-signature transaction:&lt;br /&gt;
 scriptSig: 0 &amp;lt;sig1&amp;gt; ... &amp;lt;script&amp;gt;&lt;br /&gt;
 script: OP_m &amp;lt;pubKey1&amp;gt; ... OP_n OP_CHECKMULTISIG&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
P2SH addresses were created with the motivation of moving &amp;quot;the responsibility for supplying the conditions to redeem a transaction from the sender of the funds to the redeemer. They allow the sender to fund an arbitrary transaction, no matter how complicated, using a 20-byte hash&amp;quot;[https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki#motivation 1]. Pay-to-Pubkey-hash addresses are similarly a 20-byte hash of the public key. &lt;br /&gt;
&lt;br /&gt;
The scriptPubKey in the funding transaction is script which ensures that the script supplied in the redeeming transaction hashes to the script used to create the address. &lt;br /&gt;
&lt;br /&gt;
In the scriptSig above, &#039;signatures&#039; refers to any script which is sufficient to satisfy the following serialized script. &lt;br /&gt;
&lt;br /&gt;
Checking process:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
! Stack &lt;br /&gt;
! Script &lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
|Empty.&lt;br /&gt;
| 0 &amp;lt;sig1&amp;gt; &amp;lt;sig2&amp;gt; OP_2 &amp;lt;pubKey1&amp;gt; &amp;lt;pubKey2&amp;gt; &amp;lt;pubKey3&amp;gt; OP_3 OP_CHECKMULTISIG &lt;br /&gt;
| Only the scriptSig is used.&lt;br /&gt;
|-&lt;br /&gt;
| 0 &amp;lt;sig1&amp;gt; &amp;lt;sig2&amp;gt; OP_2 &amp;lt;pubKey1&amp;gt; &amp;lt;pubKey2&amp;gt; &amp;lt;pubKey3&amp;gt; OP_3 &lt;br /&gt;
| OP_CHECKMULTISIG &lt;br /&gt;
| Constants are added to the stack.&lt;br /&gt;
|-&lt;br /&gt;
| true&lt;br /&gt;
| Empty&lt;br /&gt;
| Signatures validated in the order of the keys in the script.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
See also [[BIP 0016]]&lt;br /&gt;
&lt;br /&gt;
==== Generation ====&lt;br /&gt;
&lt;br /&gt;
Generations have a single input, and this input has a &amp;quot;coinbase&amp;quot; parameter instead of a scriptSig. The data in &amp;quot;coinbase&amp;quot; can be anything; it isn&#039;t used. Bitcoin puts the current compact-format [[target]] and the arbitrary-precision &amp;quot;extraNonce&amp;quot; number there, which increments every time the Nonce field in the [[block_hashing_algorithm|block header]] overflows. Outputs can be anything, but Bitcoin creates one exactly like an IP address transaction.&lt;br /&gt;
The extranonce contributes to enlarge the domain for the proof of work function. Miners can easily modify nonce (4byte), timestamp and extranonce (2 to 100bytes).&lt;br /&gt;
&lt;br /&gt;
=== general format (inside a block) of each input of a transaction - Txin ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Description&lt;br /&gt;
! Size&lt;br /&gt;
|-&lt;br /&gt;
|Previous Transaction hash &lt;br /&gt;
| doubled [[Wikipedia:SHA-256|SHA256]]-[[hash|hashed]] of a (previous) to-be-used transaction&lt;br /&gt;
|32 bytes&lt;br /&gt;
|-&lt;br /&gt;
|Previous Txout-index&lt;br /&gt;
| non negative integer indexing an output of the to-be-used transaction&lt;br /&gt;
|4 bytes&lt;br /&gt;
|-&lt;br /&gt;
|Txin-script length&lt;br /&gt;
|non negative integer [[ Protocol_specification#Variable_length_integer|VI = VarInt]]&lt;br /&gt;
|1 - 9 bytes&lt;br /&gt;
|-&lt;br /&gt;
|Txin-script / scriptSig&lt;br /&gt;
|[[Script]]&lt;br /&gt;
|&amp;lt;in-script length&amp;gt;-many bytes&lt;br /&gt;
|-&lt;br /&gt;
|sequence_no&lt;br /&gt;
|normally 0xFFFFFFFF; irrelevant unless transaction&#039;s lock_time is &amp;gt; 0&lt;br /&gt;
|4 bytes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The input sufficiently describes where and how to get the bitcoin amout to be redeemed.&lt;br /&gt;
If it is the (only) input of the first transaction of a block, it is called the generation transaction input and its content completely ignored. (Historically the Previous Transaction hash is 0 and the Previous Txout-index is -1.)&lt;br /&gt;
&lt;br /&gt;
=== general format (inside a block) of each output of a transaction - Txout ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Description&lt;br /&gt;
! Size&lt;br /&gt;
|-&lt;br /&gt;
|value&lt;br /&gt;
|non negative integer giving the number of [[FAQ#What_do_I_call_the_various_denominations_of_bitcoins.3F|Satoshis(BTC/10^8)]] to be transfered&lt;br /&gt;
|8 bytes&lt;br /&gt;
|-&lt;br /&gt;
|Txout-script length&lt;br /&gt;
|non negative integer&lt;br /&gt;
|1 - 9 bytes [[ Protocol_specification#Variable_length_integer|VI = VarInt]]&lt;br /&gt;
|-&lt;br /&gt;
|Txout-script / scriptPubKey&lt;br /&gt;
|[[Script]]&lt;br /&gt;
|&amp;lt;out-script length&amp;gt;-many bytes&lt;br /&gt;
|}&lt;br /&gt;
The output sets the conditions to release this bitcoin amount later. The sum of the output values of the first transaction is the value of the mined bitcoins for the block plus possible transactions fees of the other transactions in the block.&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
&lt;br /&gt;
* [[Script]]&lt;br /&gt;
* [[BTC Sender]] Transmit raw, hand-crafted transactions&lt;br /&gt;
* [[Raw Transactions]]&lt;br /&gt;
* [[Transaction Malleability]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;br /&gt;
[[de:Transaktion]]&lt;br /&gt;
[[es:Transacción]]&lt;br /&gt;
[[pl:Transakcje]]&lt;/div&gt;</summary>
		<author><name>Tkerin</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Transaction&amp;diff=47016</id>
		<title>Transaction</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Transaction&amp;diff=47016"/>
		<updated>2014-05-05T23:54:29Z</updated>

		<summary type="html">&lt;p&gt;Tkerin: /* Pay-to-ScriptHash */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:TxBinaryMap.png|thumb|right|Byte-map of Transaction with each type of TxIn and TxOut]]&lt;br /&gt;
A &#039;&#039;&#039;transaction&#039;&#039;&#039; is a signed section of data that is broadcast to the [[network]] and collected into [[block|blocks]]. It typically references previous transaction(s) and dedicates a certain number of bitcoins from it to one or more new public key(s) (Bitcoin address). It is not encrypted (nothing in Bitcoin is encrypted).&lt;br /&gt;
&lt;br /&gt;
A [[block chain browser]] is a site where every transaction included within the block chain can be viewed.  This is useful for seeing the technical details of transaction in action, and for payment verification purposes.&lt;br /&gt;
&lt;br /&gt;
=== general format of a Bitcoin transaction (inside a block) ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Description&lt;br /&gt;
! Size&lt;br /&gt;
|-&lt;br /&gt;
|Version no&lt;br /&gt;
|currently 1&lt;br /&gt;
|4 bytes&lt;br /&gt;
|-&lt;br /&gt;
|In-counter&lt;br /&gt;
| positive integer [[ Protocol_specification#Variable_length_integer|VI = VarInt]]&lt;br /&gt;
| 1 - 9 bytes &lt;br /&gt;
|-&lt;br /&gt;
|list of inputs&lt;br /&gt;
|[[Transactions#general_format_.28inside_a_block.29_of_each_input_of_a_transaction_-_Txin|the first input of the first transaction is also called &amp;quot;coinbase&amp;quot; (its content was ignored in earlier versions)]]&lt;br /&gt;
|&amp;lt;in-counter&amp;gt;-many inputs&lt;br /&gt;
|-&lt;br /&gt;
|Out-counter&lt;br /&gt;
| positive integer [[ Protocol_specification#Variable_length_integer|VI = VarInt]]&lt;br /&gt;
| 1 - 9 bytes&lt;br /&gt;
|-&lt;br /&gt;
|list of outputs&lt;br /&gt;
|[[Transactions#general_format_.28inside_a_block.29_of_each_output_of_a_transaction_-_Txout|the outputs of the first transaction spend the mined bitcoins for the block]]&lt;br /&gt;
|&amp;lt;out-counter&amp;gt;-many outputs&lt;br /&gt;
|-&lt;br /&gt;
|lock_time&lt;br /&gt;
|if non-zero and sequence numbers are &amp;lt; 0xFFFFFFFF: block height or timestamp when transaction is final&lt;br /&gt;
|4 bytes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Principle example of a Bitcoin transaction with 1 input and 1 output only ===&lt;br /&gt;
&lt;br /&gt;
==== Data ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Input:&lt;br /&gt;
Previous tx: f5d8ee39a430901c91a5917b9f2dc19d6d1a0e9cea205b009ca73dd04470b9a6&lt;br /&gt;
Index: 0&lt;br /&gt;
scriptSig: 304502206e21798a42fae0e854281abd38bacd1aeed3ee3738d9e1446618c4571d10&lt;br /&gt;
90db022100e2ac980643b0b82c0e88ffdfec6b64e3e6ba35e7ba5fdd7d5d6cc8d25c6b241501&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
Value: 5000000000&lt;br /&gt;
scriptPubKey: OP_DUP OP_HASH160 404371705fa9bd789a2fcd52d2c580b65d35549d&lt;br /&gt;
OP_EQUALVERIFY OP_CHECKSIG&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Explanation ====&lt;br /&gt;
&lt;br /&gt;
The input in this transaction imports 50 BTC from output #0 in transaction f5d8... Then the output sends 50 BTC to a Bitcoin address (expressed here in hexadecimal 4043... instead of the normal base58). When the recipient wants to spend this money, he will reference output #0 of this transaction in an input of his own transaction.&lt;br /&gt;
&lt;br /&gt;
===== Input =====&lt;br /&gt;
&lt;br /&gt;
An &#039;&#039;&#039;input&#039;&#039;&#039; is a reference to an output in a different transaction. Multiple inputs are often listed in a transaction. The values of the referenced outputs are added up, and the total is usable in the outputs of this transaction. &#039;&#039;&#039;Previous tx&#039;&#039;&#039; is a [[hash]] of a previous transaction. &#039;&#039;&#039;Index&#039;&#039;&#039; is the specific output in the referenced transaction. &#039;&#039;&#039;ScriptSig&#039;&#039;&#039; is the first half of a [[script]] (discussed in more detail later).&lt;br /&gt;
&lt;br /&gt;
The script contains two components, a signature and a public key. The public key belongs to the redeemer of the output transaction and proves the creator is allowed to redeem the outputs value. The other component is an ECDSA signature over a hash of a simplified version of the transaction. It, combined with the public key, proves the transaction was created by the real owner of the address in question. Various flags define how the transaction is simplified and can be used to create different types of payment.&lt;br /&gt;
&lt;br /&gt;
===== Output =====&lt;br /&gt;
&lt;br /&gt;
An &#039;&#039;&#039;output&#039;&#039;&#039; contains instructions for sending bitcoins. &#039;&#039;&#039;Value&#039;&#039;&#039; is the number of Satoshi (1 BTC = 100,000,000 Satoshi) that this output will be worth when claimed. &#039;&#039;&#039;ScriptPubKey&#039;&#039;&#039; is the second half of a script (discussed later). There can be more than one output, and they share the combined value of the inputs. Because each output from one transaction can only ever be referenced once by an input of a subsequent transaction, the entire combined input value needs to be sent in an output if you don&#039;t want to lose it. If the input is worth 50 BTC but you only want to send 25 BTC, Bitcoin will create two outputs worth 25 BTC: one to the destination, and one back to you (known as &amp;quot;[[change]]&amp;quot;, though you send it to yourself). Any input bitcoins not redeemed in an output is considered a [[transaction fee]]; whoever generates the block will get it.&lt;br /&gt;
[[File:transaction.png|thumb|A sends 100 BTC to C and C generates 50 BTC. C sends 101 BTC to D, and he needs to send himself some change. D sends the 101 BTC to someone else, but they haven&#039;t redeemed it yet. Only D&#039;s output and C&#039;s change are capable of being spent in the current state.]]&lt;br /&gt;
&lt;br /&gt;
===== Verification =====&lt;br /&gt;
&lt;br /&gt;
To verify that inputs are authorized to collect the values of referenced outputs, Bitcoin uses a custom Forth-like [[script|scripting]] system. The input&#039;s scriptSig and the &#039;&#039;referenced&#039;&#039; output&#039;s scriptPubKey are evaluated (in that order), with scriptPubKey using the values left on the stack by scriptSig. The input is authorized if scriptPubKey returns true. Through the scripting system, the sender can create very complex conditions that people have to meet in order to claim the output&#039;s value. For example, it&#039;s possible to create an output that can be claimed by anyone without any authorization. It&#039;s also possible to require that an input be signed by ten different keys, or be redeemable with a password instead of a key.&lt;br /&gt;
&lt;br /&gt;
=== Types of Transaction ===&lt;br /&gt;
Bitcoin currently creates two different scriptSig/scriptPubKey pairs. These are described below.&lt;br /&gt;
&lt;br /&gt;
It is possible to design more complex types of transactions, and link them together into cryptographically enforced agreements. These are known as [[Contracts]].&lt;br /&gt;
&lt;br /&gt;
==== Pay-to-PubkeyHash ====&lt;br /&gt;
&lt;br /&gt;
 scriptPubKey: OP_DUP OP_HASH160 &amp;lt;pubKeyHash&amp;gt; OP_EQUALVERIFY OP_CHECKSIG&lt;br /&gt;
 scriptSig: &amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt;&lt;br /&gt;
A Bitcoin [[address]] is only a hash, so the sender can&#039;t provide a full public key in scriptPubKey. When redeeming coins that have been sent to a Bitcoin address, the recipient provides both the signature and the public key. The script verifies that the provided public key does hash to the hash in scriptPubKey, and then it also checks the signature against the public key.&lt;br /&gt;
&lt;br /&gt;
Checking process:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
! Stack &lt;br /&gt;
! Script &lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
|Empty.&lt;br /&gt;
| &amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt; OP_DUP OP_HASH160 &amp;lt;pubKeyHash&amp;gt; OP_EQUALVERIFY OP_CHECKSIG &lt;br /&gt;
| scriptSig and scriptPubKey are combined.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt;&lt;br /&gt;
| OP_DUP OP_HASH160 &amp;lt;pubKeyHash&amp;gt; OP_EQUALVERIFY OP_CHECKSIG &lt;br /&gt;
| Constants are added to the stack.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt; &amp;lt;pubKey&amp;gt;&lt;br /&gt;
| OP_HASH160 &amp;lt;pubKeyHash&amp;gt; OP_EQUALVERIFY OP_CHECKSIG &lt;br /&gt;
| Top stack item is duplicated.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt; &amp;lt;pubHashA&amp;gt;&lt;br /&gt;
|&amp;lt;pubKeyHash&amp;gt; OP_EQUALVERIFY OP_CHECKSIG&lt;br /&gt;
| Top stack item is hashed.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt; &amp;lt;pubHashA&amp;gt; &amp;lt;pubKeyHash&amp;gt;&lt;br /&gt;
|OP_EQUALVERIFY OP_CHECKSIG&lt;br /&gt;
| Constant added.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt;&lt;br /&gt;
|OP_CHECKSIG&lt;br /&gt;
| Equality is checked between the top two stack items.&lt;br /&gt;
|-&lt;br /&gt;
|true&lt;br /&gt;
|Empty.&lt;br /&gt;
|Signature is checked for top two stack items.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Pay-to-ScriptHash ====&lt;br /&gt;
&lt;br /&gt;
 scriptPubKey: OP_HASH160 &amp;lt;scriptHash&amp;gt; OP_EQUAL &lt;br /&gt;
 scriptSig: ..signatures... &amp;lt;serialized script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 m-of-n multi-signature transaction:&lt;br /&gt;
 scriptSig: 0 &amp;lt;sig1&amp;gt; ... &amp;lt;script&amp;gt;&lt;br /&gt;
 script: OP_m &amp;lt;pubKey1&amp;gt; ... OP_n OP_CHECKMULTISIG&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
P2SH addresses were created with the motivation of moving &amp;quot;the responsibility for supplying the conditions to redeem a transaction from the sender of the funds to the redeemer. They allow the sender to fund an arbitrary transaction, no matter how complicated, using a 20-byte hash&amp;quot;[https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki#motivation 1]. Pay-to-Pubkey-hash addresses are similarly a 20-byte hash of the public key. &lt;br /&gt;
&lt;br /&gt;
The scriptPubKey in the funding transaction is script which ensures that the script supplied in the redeeming transaction hashes to the script used to create the address. &lt;br /&gt;
&lt;br /&gt;
In the scriptSig above, &#039;signatures&#039; refers to any script which is sufficient to satisfy the following serialized script. &lt;br /&gt;
&lt;br /&gt;
Checking process:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
! Stack &lt;br /&gt;
! Script &lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
|Empty.&lt;br /&gt;
| 0 &amp;lt;sig1&amp;gt; &amp;lt;sig2&amp;gt; OP_2 &amp;lt;pubKey1&amp;gt; &amp;lt;pubKey2&amp;gt; &amp;lt;pubKey3&amp;gt; OP_3 OP_CHECKMULTISIG &lt;br /&gt;
| Only the scriptSig is used.&lt;br /&gt;
|-&lt;br /&gt;
| 0 &amp;lt;sig1&amp;gt; &amp;lt;sig2&amp;gt; OP_2 &amp;lt;pubKey1&amp;gt; &amp;lt;pubKey2&amp;gt; &amp;lt;pubKey3&amp;gt; OP_3 &lt;br /&gt;
| OP_CHECKMULTISIG &lt;br /&gt;
| Constants are added to the stack.&lt;br /&gt;
|-&lt;br /&gt;
| true&lt;br /&gt;
| Empty&lt;br /&gt;
| Signatures validated in the order of the keys in the script.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
See also [[BIP 0016]]&lt;br /&gt;
&lt;br /&gt;
==== Generation ====&lt;br /&gt;
&lt;br /&gt;
Generations have a single input, and this input has a &amp;quot;coinbase&amp;quot; parameter instead of a scriptSig. The data in &amp;quot;coinbase&amp;quot; can be anything; it isn&#039;t used. Bitcoin puts the current compact-format [[target]] and the arbitrary-precision &amp;quot;extraNonce&amp;quot; number there, which increments every time the Nonce field in the [[block_hashing_algorithm|block header]] overflows. Outputs can be anything, but Bitcoin creates one exactly like an IP address transaction.&lt;br /&gt;
The extranonce contributes to enlarge the domain for the proof of work function. Miners can easily modify nonce (4byte), timestamp and extranonce (2 to 100bytes).&lt;br /&gt;
&lt;br /&gt;
=== general format (inside a block) of each input of a transaction - Txin ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Description&lt;br /&gt;
! Size&lt;br /&gt;
|-&lt;br /&gt;
|Previous Transaction hash &lt;br /&gt;
| doubled [[Wikipedia:SHA-256|SHA256]]-[[hash|hashed]] of a (previous) to-be-used transaction&lt;br /&gt;
|32 bytes&lt;br /&gt;
|-&lt;br /&gt;
|Previous Txout-index&lt;br /&gt;
| non negative integer indexing an output of the to-be-used transaction&lt;br /&gt;
|4 bytes&lt;br /&gt;
|-&lt;br /&gt;
|Txin-script length&lt;br /&gt;
|non negative integer [[ Protocol_specification#Variable_length_integer|VI = VarInt]]&lt;br /&gt;
|1 - 9 bytes&lt;br /&gt;
|-&lt;br /&gt;
|Txin-script / scriptSig&lt;br /&gt;
|[[Script]]&lt;br /&gt;
|&amp;lt;in-script length&amp;gt;-many bytes&lt;br /&gt;
|-&lt;br /&gt;
|sequence_no&lt;br /&gt;
|normally 0xFFFFFFFF; irrelevant unless transaction&#039;s lock_time is &amp;gt; 0&lt;br /&gt;
|4 bytes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The input sufficiently describes where and how to get the bitcoin amout to be redeemed.&lt;br /&gt;
If it is the (only) input of the first transaction of a block, it is called the generation transaction input and its content completely ignored. (Historically the Previous Transaction hash is 0 and the Previous Txout-index is -1.)&lt;br /&gt;
&lt;br /&gt;
=== general format (inside a block) of each output of a transaction - Txout ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Description&lt;br /&gt;
! Size&lt;br /&gt;
|-&lt;br /&gt;
|value&lt;br /&gt;
|non negative integer giving the number of [[FAQ#What_do_I_call_the_various_denominations_of_bitcoins.3F|Satoshis(BTC/10^8)]] to be transfered&lt;br /&gt;
|8 bytes&lt;br /&gt;
|-&lt;br /&gt;
|Txout-script length&lt;br /&gt;
|non negative integer&lt;br /&gt;
|1 - 9 bytes [[ Protocol_specification#Variable_length_integer|VI = VarInt]]&lt;br /&gt;
|-&lt;br /&gt;
|Txout-script / scriptPubKey&lt;br /&gt;
|[[Script]]&lt;br /&gt;
|&amp;lt;out-script length&amp;gt;-many bytes&lt;br /&gt;
|}&lt;br /&gt;
The output sets the conditions to release this bitcoin amount later. The sum of the output values of the first transaction is the value of the mined bitcoins for the block plus possible transactions fees of the other transactions in the block.&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
&lt;br /&gt;
* [[Script]]&lt;br /&gt;
* [[BTC Sender]] Transmit raw, hand-crafted transactions&lt;br /&gt;
* [[Raw Transactions]]&lt;br /&gt;
* [[Transaction Malleability]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;br /&gt;
[[de:Transaktion]]&lt;br /&gt;
[[es:Transacción]]&lt;br /&gt;
[[pl:Transakcje]]&lt;/div&gt;</summary>
		<author><name>Tkerin</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=Transaction&amp;diff=47015</id>
		<title>Transaction</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=Transaction&amp;diff=47015"/>
		<updated>2014-05-05T23:53:27Z</updated>

		<summary type="html">&lt;p&gt;Tkerin: /* Pay-to-ScriptHash */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:TxBinaryMap.png|thumb|right|Byte-map of Transaction with each type of TxIn and TxOut]]&lt;br /&gt;
A &#039;&#039;&#039;transaction&#039;&#039;&#039; is a signed section of data that is broadcast to the [[network]] and collected into [[block|blocks]]. It typically references previous transaction(s) and dedicates a certain number of bitcoins from it to one or more new public key(s) (Bitcoin address). It is not encrypted (nothing in Bitcoin is encrypted).&lt;br /&gt;
&lt;br /&gt;
A [[block chain browser]] is a site where every transaction included within the block chain can be viewed.  This is useful for seeing the technical details of transaction in action, and for payment verification purposes.&lt;br /&gt;
&lt;br /&gt;
=== general format of a Bitcoin transaction (inside a block) ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Description&lt;br /&gt;
! Size&lt;br /&gt;
|-&lt;br /&gt;
|Version no&lt;br /&gt;
|currently 1&lt;br /&gt;
|4 bytes&lt;br /&gt;
|-&lt;br /&gt;
|In-counter&lt;br /&gt;
| positive integer [[ Protocol_specification#Variable_length_integer|VI = VarInt]]&lt;br /&gt;
| 1 - 9 bytes &lt;br /&gt;
|-&lt;br /&gt;
|list of inputs&lt;br /&gt;
|[[Transactions#general_format_.28inside_a_block.29_of_each_input_of_a_transaction_-_Txin|the first input of the first transaction is also called &amp;quot;coinbase&amp;quot; (its content was ignored in earlier versions)]]&lt;br /&gt;
|&amp;lt;in-counter&amp;gt;-many inputs&lt;br /&gt;
|-&lt;br /&gt;
|Out-counter&lt;br /&gt;
| positive integer [[ Protocol_specification#Variable_length_integer|VI = VarInt]]&lt;br /&gt;
| 1 - 9 bytes&lt;br /&gt;
|-&lt;br /&gt;
|list of outputs&lt;br /&gt;
|[[Transactions#general_format_.28inside_a_block.29_of_each_output_of_a_transaction_-_Txout|the outputs of the first transaction spend the mined bitcoins for the block]]&lt;br /&gt;
|&amp;lt;out-counter&amp;gt;-many outputs&lt;br /&gt;
|-&lt;br /&gt;
|lock_time&lt;br /&gt;
|if non-zero and sequence numbers are &amp;lt; 0xFFFFFFFF: block height or timestamp when transaction is final&lt;br /&gt;
|4 bytes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Principle example of a Bitcoin transaction with 1 input and 1 output only ===&lt;br /&gt;
&lt;br /&gt;
==== Data ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Input:&lt;br /&gt;
Previous tx: f5d8ee39a430901c91a5917b9f2dc19d6d1a0e9cea205b009ca73dd04470b9a6&lt;br /&gt;
Index: 0&lt;br /&gt;
scriptSig: 304502206e21798a42fae0e854281abd38bacd1aeed3ee3738d9e1446618c4571d10&lt;br /&gt;
90db022100e2ac980643b0b82c0e88ffdfec6b64e3e6ba35e7ba5fdd7d5d6cc8d25c6b241501&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
Value: 5000000000&lt;br /&gt;
scriptPubKey: OP_DUP OP_HASH160 404371705fa9bd789a2fcd52d2c580b65d35549d&lt;br /&gt;
OP_EQUALVERIFY OP_CHECKSIG&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Explanation ====&lt;br /&gt;
&lt;br /&gt;
The input in this transaction imports 50 BTC from output #0 in transaction f5d8... Then the output sends 50 BTC to a Bitcoin address (expressed here in hexadecimal 4043... instead of the normal base58). When the recipient wants to spend this money, he will reference output #0 of this transaction in an input of his own transaction.&lt;br /&gt;
&lt;br /&gt;
===== Input =====&lt;br /&gt;
&lt;br /&gt;
An &#039;&#039;&#039;input&#039;&#039;&#039; is a reference to an output in a different transaction. Multiple inputs are often listed in a transaction. The values of the referenced outputs are added up, and the total is usable in the outputs of this transaction. &#039;&#039;&#039;Previous tx&#039;&#039;&#039; is a [[hash]] of a previous transaction. &#039;&#039;&#039;Index&#039;&#039;&#039; is the specific output in the referenced transaction. &#039;&#039;&#039;ScriptSig&#039;&#039;&#039; is the first half of a [[script]] (discussed in more detail later).&lt;br /&gt;
&lt;br /&gt;
The script contains two components, a signature and a public key. The public key belongs to the redeemer of the output transaction and proves the creator is allowed to redeem the outputs value. The other component is an ECDSA signature over a hash of a simplified version of the transaction. It, combined with the public key, proves the transaction was created by the real owner of the address in question. Various flags define how the transaction is simplified and can be used to create different types of payment.&lt;br /&gt;
&lt;br /&gt;
===== Output =====&lt;br /&gt;
&lt;br /&gt;
An &#039;&#039;&#039;output&#039;&#039;&#039; contains instructions for sending bitcoins. &#039;&#039;&#039;Value&#039;&#039;&#039; is the number of Satoshi (1 BTC = 100,000,000 Satoshi) that this output will be worth when claimed. &#039;&#039;&#039;ScriptPubKey&#039;&#039;&#039; is the second half of a script (discussed later). There can be more than one output, and they share the combined value of the inputs. Because each output from one transaction can only ever be referenced once by an input of a subsequent transaction, the entire combined input value needs to be sent in an output if you don&#039;t want to lose it. If the input is worth 50 BTC but you only want to send 25 BTC, Bitcoin will create two outputs worth 25 BTC: one to the destination, and one back to you (known as &amp;quot;[[change]]&amp;quot;, though you send it to yourself). Any input bitcoins not redeemed in an output is considered a [[transaction fee]]; whoever generates the block will get it.&lt;br /&gt;
[[File:transaction.png|thumb|A sends 100 BTC to C and C generates 50 BTC. C sends 101 BTC to D, and he needs to send himself some change. D sends the 101 BTC to someone else, but they haven&#039;t redeemed it yet. Only D&#039;s output and C&#039;s change are capable of being spent in the current state.]]&lt;br /&gt;
&lt;br /&gt;
===== Verification =====&lt;br /&gt;
&lt;br /&gt;
To verify that inputs are authorized to collect the values of referenced outputs, Bitcoin uses a custom Forth-like [[script|scripting]] system. The input&#039;s scriptSig and the &#039;&#039;referenced&#039;&#039; output&#039;s scriptPubKey are evaluated (in that order), with scriptPubKey using the values left on the stack by scriptSig. The input is authorized if scriptPubKey returns true. Through the scripting system, the sender can create very complex conditions that people have to meet in order to claim the output&#039;s value. For example, it&#039;s possible to create an output that can be claimed by anyone without any authorization. It&#039;s also possible to require that an input be signed by ten different keys, or be redeemable with a password instead of a key.&lt;br /&gt;
&lt;br /&gt;
=== Types of Transaction ===&lt;br /&gt;
Bitcoin currently creates two different scriptSig/scriptPubKey pairs. These are described below.&lt;br /&gt;
&lt;br /&gt;
It is possible to design more complex types of transactions, and link them together into cryptographically enforced agreements. These are known as [[Contracts]].&lt;br /&gt;
&lt;br /&gt;
==== Pay-to-PubkeyHash ====&lt;br /&gt;
&lt;br /&gt;
 scriptPubKey: OP_DUP OP_HASH160 &amp;lt;pubKeyHash&amp;gt; OP_EQUALVERIFY OP_CHECKSIG&lt;br /&gt;
 scriptSig: &amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt;&lt;br /&gt;
A Bitcoin [[address]] is only a hash, so the sender can&#039;t provide a full public key in scriptPubKey. When redeeming coins that have been sent to a Bitcoin address, the recipient provides both the signature and the public key. The script verifies that the provided public key does hash to the hash in scriptPubKey, and then it also checks the signature against the public key.&lt;br /&gt;
&lt;br /&gt;
Checking process:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
! Stack &lt;br /&gt;
! Script &lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
|Empty.&lt;br /&gt;
| &amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt; OP_DUP OP_HASH160 &amp;lt;pubKeyHash&amp;gt; OP_EQUALVERIFY OP_CHECKSIG &lt;br /&gt;
| scriptSig and scriptPubKey are combined.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt;&lt;br /&gt;
| OP_DUP OP_HASH160 &amp;lt;pubKeyHash&amp;gt; OP_EQUALVERIFY OP_CHECKSIG &lt;br /&gt;
| Constants are added to the stack.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt; &amp;lt;pubKey&amp;gt;&lt;br /&gt;
| OP_HASH160 &amp;lt;pubKeyHash&amp;gt; OP_EQUALVERIFY OP_CHECKSIG &lt;br /&gt;
| Top stack item is duplicated.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt; &amp;lt;pubHashA&amp;gt;&lt;br /&gt;
|&amp;lt;pubKeyHash&amp;gt; OP_EQUALVERIFY OP_CHECKSIG&lt;br /&gt;
| Top stack item is hashed.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt; &amp;lt;pubHashA&amp;gt; &amp;lt;pubKeyHash&amp;gt;&lt;br /&gt;
|OP_EQUALVERIFY OP_CHECKSIG&lt;br /&gt;
| Constant added.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;sig&amp;gt; &amp;lt;pubKey&amp;gt;&lt;br /&gt;
|OP_CHECKSIG&lt;br /&gt;
| Equality is checked between the top two stack items.&lt;br /&gt;
|-&lt;br /&gt;
|true&lt;br /&gt;
|Empty.&lt;br /&gt;
|Signature is checked for top two stack items.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Pay-to-ScriptHash ====&lt;br /&gt;
&lt;br /&gt;
 scriptPubKey: OP_HASH160 &amp;lt;scriptHash&amp;gt; OP_EQUAL &lt;br /&gt;
 scriptSig: ..signatures... &amp;lt;serialized script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 m-of-n multi-signature transaction:&lt;br /&gt;
 scriptSig: 0 &amp;lt;sig1&amp;gt; ... &amp;lt;script&amp;gt;&lt;br /&gt;
 script: OP_m &amp;lt;pubKey1&amp;gt; ... OP_n OP_CHECKMULTISIG&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
P2SH addresses were created with the motivation of moving &amp;quot;the responsibility for supplying the conditions to redeem a transaction from the sender of the funds to the redeemer. They allow the sender to fund an arbitrary transaction, no matter how complicated, using a 20-byte hash&amp;quot;[https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki#motivation 1]. Pay-to-Pubkey-hash addresses are similarly a 20-byte hash of the public key. &lt;br /&gt;
&lt;br /&gt;
The scriptPubKey in the funding transaction is script which ensures that the script supplied in the redeeming transaction hashes to the script used to create the address. &lt;br /&gt;
&lt;br /&gt;
In the scriptSig above, &#039;signatures&#039; refers to any script which is sufficient to satisfy the following serialized script. &lt;br /&gt;
&lt;br /&gt;
While multi-signature transactions are the most common P2SH address, there is one other simple example:&lt;br /&gt;
http://webbtc.com/tx/112ae9859731f671ec3593de5790ed026d06d23134ba284aec811bc8f50e96b3 - the 7th P2SH transaction recorded in the blockchain.&lt;br /&gt;
&lt;br /&gt;
This transaction redeems funds sent to the address 37paP4uTjmA4Pi85LG6CF9huift3Dw1kFT. The script is revealed to be: 5357; which when interpreted just leaves the stack with two numbers: 3 and 7. Since this is non-zero, the script evaluates to true - anyone with knowledge of the script could have redeemed the funds. &lt;br /&gt;
&lt;br /&gt;
This is a simple use of P2SH compared to multi-signature transactions, and many more are possible.&lt;br /&gt;
&lt;br /&gt;
Checking process:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
! Stack &lt;br /&gt;
! Script &lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
|Empty.&lt;br /&gt;
| 0 &amp;lt;sig1&amp;gt; &amp;lt;sig2&amp;gt; OP_2 &amp;lt;pubKey1&amp;gt; &amp;lt;pubKey2&amp;gt; &amp;lt;pubKey3&amp;gt; OP_3 OP_CHECKMULTISIG &lt;br /&gt;
| Only the scriptSig is used.&lt;br /&gt;
|-&lt;br /&gt;
| 0 &amp;lt;sig1&amp;gt; &amp;lt;sig2&amp;gt; OP_2 &amp;lt;pubKey1&amp;gt; &amp;lt;pubKey2&amp;gt; &amp;lt;pubKey3&amp;gt; OP_3 &lt;br /&gt;
| OP_CHECKMULTISIG &lt;br /&gt;
| Constants are added to the stack.&lt;br /&gt;
|-&lt;br /&gt;
| true&lt;br /&gt;
| Empty&lt;br /&gt;
| Signatures validated in the order of the keys in the script.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
See also [[BIP 0016]]&lt;br /&gt;
&lt;br /&gt;
==== Generation ====&lt;br /&gt;
&lt;br /&gt;
Generations have a single input, and this input has a &amp;quot;coinbase&amp;quot; parameter instead of a scriptSig. The data in &amp;quot;coinbase&amp;quot; can be anything; it isn&#039;t used. Bitcoin puts the current compact-format [[target]] and the arbitrary-precision &amp;quot;extraNonce&amp;quot; number there, which increments every time the Nonce field in the [[block_hashing_algorithm|block header]] overflows. Outputs can be anything, but Bitcoin creates one exactly like an IP address transaction.&lt;br /&gt;
The extranonce contributes to enlarge the domain for the proof of work function. Miners can easily modify nonce (4byte), timestamp and extranonce (2 to 100bytes).&lt;br /&gt;
&lt;br /&gt;
=== general format (inside a block) of each input of a transaction - Txin ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Description&lt;br /&gt;
! Size&lt;br /&gt;
|-&lt;br /&gt;
|Previous Transaction hash &lt;br /&gt;
| doubled [[Wikipedia:SHA-256|SHA256]]-[[hash|hashed]] of a (previous) to-be-used transaction&lt;br /&gt;
|32 bytes&lt;br /&gt;
|-&lt;br /&gt;
|Previous Txout-index&lt;br /&gt;
| non negative integer indexing an output of the to-be-used transaction&lt;br /&gt;
|4 bytes&lt;br /&gt;
|-&lt;br /&gt;
|Txin-script length&lt;br /&gt;
|non negative integer [[ Protocol_specification#Variable_length_integer|VI = VarInt]]&lt;br /&gt;
|1 - 9 bytes&lt;br /&gt;
|-&lt;br /&gt;
|Txin-script / scriptSig&lt;br /&gt;
|[[Script]]&lt;br /&gt;
|&amp;lt;in-script length&amp;gt;-many bytes&lt;br /&gt;
|-&lt;br /&gt;
|sequence_no&lt;br /&gt;
|normally 0xFFFFFFFF; irrelevant unless transaction&#039;s lock_time is &amp;gt; 0&lt;br /&gt;
|4 bytes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The input sufficiently describes where and how to get the bitcoin amout to be redeemed.&lt;br /&gt;
If it is the (only) input of the first transaction of a block, it is called the generation transaction input and its content completely ignored. (Historically the Previous Transaction hash is 0 and the Previous Txout-index is -1.)&lt;br /&gt;
&lt;br /&gt;
=== general format (inside a block) of each output of a transaction - Txout ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Description&lt;br /&gt;
! Size&lt;br /&gt;
|-&lt;br /&gt;
|value&lt;br /&gt;
|non negative integer giving the number of [[FAQ#What_do_I_call_the_various_denominations_of_bitcoins.3F|Satoshis(BTC/10^8)]] to be transfered&lt;br /&gt;
|8 bytes&lt;br /&gt;
|-&lt;br /&gt;
|Txout-script length&lt;br /&gt;
|non negative integer&lt;br /&gt;
|1 - 9 bytes [[ Protocol_specification#Variable_length_integer|VI = VarInt]]&lt;br /&gt;
|-&lt;br /&gt;
|Txout-script / scriptPubKey&lt;br /&gt;
|[[Script]]&lt;br /&gt;
|&amp;lt;out-script length&amp;gt;-many bytes&lt;br /&gt;
|}&lt;br /&gt;
The output sets the conditions to release this bitcoin amount later. The sum of the output values of the first transaction is the value of the mined bitcoins for the block plus possible transactions fees of the other transactions in the block.&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
&lt;br /&gt;
* [[Script]]&lt;br /&gt;
* [[BTC Sender]] Transmit raw, hand-crafted transactions&lt;br /&gt;
* [[Raw Transactions]]&lt;br /&gt;
* [[Transaction Malleability]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;br /&gt;
[[de:Transaktion]]&lt;br /&gt;
[[es:Transacción]]&lt;br /&gt;
[[pl:Transakcje]]&lt;/div&gt;</summary>
		<author><name>Tkerin</name></author>
	</entry>
</feed>