Transaction - Bitcoin Wiki (2024)

A transaction is a transfer of Bitcoin value that is broadcast to the network and collected into blocks. A transaction typically references previous transaction outputs as new transaction inputs and dedicates all input Bitcoin values to new outputs. Transactions are not encrypted, so it is possible to browse and view every transaction ever collected into a block. Once transactions are buried under enough confirmations they can be considered irreversible.

This article is about on-chain transactions. See also: Off-Chain Transactions

Standard transaction outputs nominate addresses, and the redemption of any future inputs requires a relevant signature.

All transactions are visible in the block chain, and can be viewed with a hex editor. A block chain browser is a site where every transaction included within the block chain can be viewed in human-readable terms. This is useful for seeing the technical details of transactions in action and for verifying payments.

Contents

  • 1 General format of a Bitcoin transaction (inside a block)
  • 2 Principle example of a Bitcoin transaction with 1 input and 1 output only
    • 2.1 Data
    • 2.2 Explanation
      • 2.2.1 Input
      • 2.2.2 Output
      • 2.2.3 Witness
      • 2.2.4 Verification
  • 3 Types of Transaction
    • 3.1 Pay-to-PubkeyHash
    • 3.2 Pay-to-Script-Hash
  • 4 Generation
  • 5 General format (inside a block) of each input of a transaction - Txin
  • 6 General format (inside a block) of each output of a transaction - Txout
  • 7 See Also

General format of a Bitcoin transaction (inside a block)

FieldDescriptionSize
Version nocurrently 1. Set to 2 if you use OP_CHECKSEQUENCEVERIFY to enable timelocks4 bytes
FlagIf present, always 0001, and indicates the presence of witness dataoptional 2 byte array
In-counterpositive integer VI = VarInt1 - 9 bytes
list of inputsthe first input of the first transaction is also called "coinbase" (its content was ignored in earlier versions)<in-counter>-many inputs
Out-counterpositive integer VI = VarInt1 - 9 bytes
list of outputsthe outputs of the first transaction spend the mined bitcoins for the block<out-counter>-many outputs
WitnessesA list of witnesses, 1 for each input, omitted if flag above is missingvariable, see Segregated_Witness
lock_timeif non-zero and sequence numbers are < 0xFFFFFFFF: block height or timestamp when transaction is final4 bytes

There is no version 0 transaction - it is undefined. Versions greater than 2 are reserved for future use by the protocol. Flag and Witness are mandatory for any transaction that includes Segwit inputs, and should be omitted for legacy transactions that do not make use of Segwit.

Principle example of a Bitcoin transaction with 1 input and 1 output only

Data

Input:Previous tx: f5d8ee39a430901c91a5917b9f2dc19d6d1a0e9cea205b009ca73dd04470b9a6Index: 0scriptSig: 304502206e21798a42fae0e854281abd38bacd1aeed3ee3738d9e1446618c4571d1090db022100e2ac980643b0b82c0e88ffdfec6b64e3e6ba35e7ba5fdd7d5d6cc8d25c6b241501Output:Value: 5000000000scriptPubKey: OP_DUP OP_HASH160 404371705fa9bd789a2fcd52d2c580b65d35549dOP_EQUALVERIFY OP_CHECKSIG

Explanation

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.

Input
FieldDescriptionSize
Outpoint hashThe previous transaction that contains the spendable output32 bytes
Outpoint indexThe index within the previous transaction's output array to identify the spendable output4 bytes
Script lengthpositive integer VI = VarInt1 - 9 bytes
Script signatureInformation required to spend the output (see below for details)Variable
Sequence numberif sequence number is < 0xFFFFFFFF: Makes the transaction input Replace-By-Fee4 bytes


An input is a reference to an output from a previous transaction. Multiple inputs are often listed in a transaction. All of the new transaction's input values (that is, the total coin value of the previous outputs referenced by the new transaction's inputs) are added up, and the total (less any transaction fee) is completely used by the outputs of the new transaction. Previous tx is a hash of a previous transaction. Index is the specific output in the referenced transaction. ScriptSig is the first half of a script (discussed in more detail later).

The script contains two components, a signature and a public key. The public key must match the hash given in the script of the redeemed output. The public key is used to verify the redeemers signature, which is the second component. More precisely, the second 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 bitcoins in question. Various flags define how the transaction is simplified and can be used to create different types of payment.

Output
FieldDescriptionSize
ValueThe monetary value of the output in satoshis8 bytes
Script lengthpositive integer VI = VarInt1 - 9 bytes
ScriptA calculation which future transactions need to solve in order to spend itVariable

An output contains instructions for sending bitcoins. Value is the number of Satoshi (1 BTC = 100,000,000 Satoshi) that this output will be worth when claimed. ScriptPubKey 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'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 "change", though you send it to yourself). Any input bitcoins not redeemed in an output is considered a transaction fee; whoever generates the block can claim it by inserting it into the coinbase transaction of that block.

Witness

For Segwit transactions, there is a list of witness fields after the outputs, with each witness field corresponding to an input of the same index. Each witness field contains a varint which tells the number of elements on the witness' stack, and the stack elements themselves contains pairs of varints, signifying the length of the data, followed by the data itself.

It is important to note that when parsing a raw transaction, the witness fields are not congregated together into one "witness" field in structured, deserialized output, but each witness is placed in its own "witness" key under the respective input.

Transactions which do not have any native segwit (such as P2WPKH or P2WSH) inputs must use the legacy transaction format. Witness fields are only added for native segwit inputs, so a transaction with no such inputs cannot use the segwit transaction format, including the marker and flag. Additionally, each witness field corresponds to its respective native segwit input in the order which they are defined in the transaction. This means that in the raw transaction, the first witness field is for the first native segwit input in the transaction, and so on.

Verification

To verify that inputs are authorized to collect the values of referenced outputs, Bitcoin uses a custom Forth-like scripting system. The input's scriptSig and the referenced output'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's value. For example, it's possible to create an output that can be claimed by anyone without any authorization. It's also possible to require that an input be signed by ten different keys, or be redeemable with a password instead of a key.

Types of Transaction

Bitcoin currently creates two different scriptSig/scriptPubKey pairs. These are described below.

It is possible to design more complex types of transactions, and link them together into cryptographically enforced agreements. These are known as Contracts.

Pay-to-PubkeyHash

scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIGscriptSig: <sig> <pubKey>

A Bitcoin address is only a hash, so the sender can'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.

Checking process:

StackScriptDescription
Empty.<sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIGscriptSig and scriptPubKey are combined.
<sig> <pubKey>OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIGConstants are added to the stack.
<sig> <pubKey> <pubKey>OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIGTop stack item is duplicated.
<sig> <pubKey> <pubHashA><pubKeyHash> OP_EQUALVERIFY OP_CHECKSIGTop stack item is hashed.
<sig> <pubKey> <pubHashA> <pubKeyHash>OP_EQUALVERIFY OP_CHECKSIGConstant added.
<sig> <pubKey>OP_CHECKSIGEquality is checked between the top two stack items.
trueEmpty.Signature is checked for top two stack items.

Pay-to-Script-Hash

scriptPubKey: OP_HASH160 <scriptHash> OP_EQUAL scriptSig: ..signatures... <serialized script>
m-of-n multi-signature transaction:scriptSig: 0 <sig1> ... <script>script: OP_m <pubKey1> ... OP_n OP_CHECKMULTISIG


P2SH addresses were created with the motivation of moving "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"1. Pay-to-Pubkey-hash addresses are similarly a 20-byte hash of the public key.

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.

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.

In the scriptSig above, 'signatures' refers to any script which is sufficient to satisfy the following serialized script.

Checking process:

StackScriptDescription
Empty.0 <sig1> <sig2> OP_2 <pubKey1> <pubKey2> <pubKey3> OP_3 OP_CHECKMULTISIGOnly the scriptSig is used.
0 <sig1> <sig2> OP_2 <pubKey1> <pubKey2> <pubKey3> OP_3OP_CHECKMULTISIGConstants are added to the stack.
trueEmptySignatures validated in the order of the keys in the script.


See also BIP 0016

Generation

Generations have a single input, and this input has a "coinbase" parameter instead of a scriptSig. The data in "coinbase" can be anything; it isn't used. Bitcoin puts the current compact-format target and the arbitrary-precision "extraNonce" number there, which increments every time the Nonce field in the block header overflows. Outputs can be anything, but Bitcoin creates one exactly like an IP address transaction.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).

General format (inside a block) of each input of a transaction - Txin

FieldDescriptionSize
Previous Transaction hashdoubled SHA256-hashed of a (previous) to-be-used transaction32 bytes
Previous Txout-indexnon negative integer indexing an output of the to-be-used transaction4 bytes
Txin-script lengthnon negative integer VI = VarInt1 - 9 bytes
Txin-script / scriptSigScript<in-script length>-many bytes
sequence_nonormally 0xFFFFFFFF; irrelevant unless transaction's lock_time is > 04 bytes

The input sufficiently describes where and how to get the bitcoin amout to be redeemed.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.)

General format (inside a block) of each output of a transaction - Txout

FieldDescriptionSize
valuenon negative integer giving the number of Satoshis(BTC/10^8) to be transfered8 bytes
Txout-script lengthnon negative integer1 - 9 bytes VI = VarInt
Txout-script / scriptPubKeyScript<out-script length>-many bytes

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.

See Also

  • Script
  • Protocol rules - "tx" messages
  • Protocol documentation - Transaction Verification
  • Raw Transactions
  • Coin analogy
  • Transaction Malleability
  • Transaction broadcasting
Transaction - Bitcoin Wiki (2024)

FAQs

What is a transaction in Bitcoin? ›

A transaction is a transfer of Bitcoin value that is broadcast to the network and collected into blocks. A transaction typically references previous transaction outputs as new transaction inputs and dedicates all input Bitcoin values to new outputs.

Can I trace a Bitcoin transaction? ›

All Bitcoin transactions are public, traceable, and permanently stored in the Bitcoin network. Bitcoin addresses are the only information used to define where bitcoins are allocated and where they are sent. These addresses are created privately by each user's wallets.

How safe is Bitcoin transaction? ›

All Bitcoin transactions are stored publicly and permanently on the network, which means anyone can see the balance and transactions of any Bitcoin address. However, the identity of the user behind an address remains unknown until information is revealed during a purchase or in other circ*mstances.

What does ₿ mean? ›

digital cash system and associated currency. Bitcoin (₿) is a digital and global money system cryptocurrency.

Are Bitcoin transactions illegal? ›

Despite its use for buying goods and services, there are still no uniform international laws that regulate Bitcoin. Many developed countries allow Bitcoin to be used, such as the U.S., Canada, and the U.K. In several countries, including China and Saudi Arabia, it is illegal to use Bitcoin.

How long does a Bitcoin transaction take? ›

In general, Bitcoin transactions usually take from one to one and half hours to complete. On occasion, a high volume of transactions taking place on the Blockchain could lead to transaction delays.

Can bitcoin transactions be reversed? ›

Can Bitcoin and other cryptocurrency transactions be reversed or cancelled? No, Bitcoin and other cryptocurrency transactions are designed to be irreversible. Consequently, it is not possible to reverse or cancel cryptocurrency transactions.

How to investigate bitcoin transactions? ›

To trace Bitcoin transactions, blockchain analysis companies closely examine patterns, addresses, and transaction flows on the blockchain. By analyzing these elements, they can gain insights into the movement of funds and potentially link them to specific owners.

How do police track Bitcoin transactions? ›

Through diligent analysis and the use of blockchain analytics tools, we managed to uncover the transaction paths and link them to real-world entities. Many local law enforcement departments are still unable to handle cryptocurrency investigations effectively.

How to confirm a bitcoin transaction? ›

A Bitcoin transaction, or any cryptocurrency transaction must be confirmed on a blockchain to verify that the transaction is legitimate. A confirmed transaction means that the transaction has been included in a block, and therefore included in the blockchain.

Does Bitcoin pay real money? ›

Miners on the Bitcoin network can be rewarded by successfully opening blocks. Bitcoins are exchangeable for fiat currency via cryptocurrency exchanges. Investors and speculators can make money from trading bitcoins.

Is Bitcoin 100% safe? ›

Is Bitcoin 100% safe? Every investment comes with some degree of risk. While Bitcoin can be stored securely, potential risks include volatility and the impact of potential regulations.

How much is $1 US in Bitcoin? ›

0.000017 BTC

What is Bitcoin secret key? ›

A private key is an alphanumeric code generated by a cryptocurrency wallet. It is used to authorize transactions and prove ownership of a blockchain asset. A private key is an integral part of cryptocurrency, and its encrypted properties help protect users from thieves and unauthorized access to their funds.

How to convert Bitcoin into US dollars? ›

Just follow these steps:
  1. Go to Crypto in your Revolut app. Visit the Crypto section in-app from the Home screen.
  2. Select your BTC balance. Tap on the BTC you hold and hit Sell.
  3. Choose your currency. ...
  4. Enter the amount you want to sell. ...
  5. Check the conversion rate of BTC to USD. ...
  6. Confirm your order.

How do I receive a Bitcoin transaction? ›

To receive bitcoin, you simply need to provide a Bitcoin address to the sender. Your wallet can generate these addresses as needed, and you can share this address with the sender via any method of communication.

Who pays for Bitcoin transactions? ›

You access your bitcoin using a wallet and private keys. Bitcoin users pay transaction fees in bitcoin to miners for processing the transactions.

How is a Bitcoin transaction confirmed? ›

A confirmation represents the acceptance of a new block (containing several transactions) by the blockchain network. Once a miner has successfully added a new block to the blockchain, one 'confirmation' has occurred. This means that the transactions within the block are verified and are now part of the blockchain.

What is the benefit of Bitcoin transaction? ›

With Bitcoin, there is no risk of charge-backs because once Bitcoin is sent, the transaction cannot be reversed. Bitcoin is akin to cash -- once you give someone cash, you cannot get it back (unless they give it back to you).

Top Articles
Explained - Importance Of Shopping | Why Shopping Is Important
What is a botted LoL account?
The Largest Banks - ​​How to Transfer Money With Only Card Number and CVV (2024)
What happened to Lori Petty? What is she doing today? Wiki
Rek Funerals
Find All Subdomains
The Idol - watch tv show streaming online
Calamity Hallowed Ore
Dark Souls 2 Soft Cap
Southland Goldendoodles
Clairememory Scam
What Does Dwb Mean In Instagram
Miami Valley Hospital Central Scheduling
How Many Slices Are In A Large Pizza? | Number Of Pizzas To Order For Your Next Party
Pwc Transparency Report
60 X 60 Christmas Tablecloths
25Cc To Tbsp
Parent Resources - Padua Franciscan High School
Noaa Ilx
Account Suspended
Hdmovie 2
Joan M. Wallace - Baker Swan Funeral Home
MyCase Pricing | Start Your 10-Day Free Trial Today
Caring Hearts For Canines Aberdeen Nc
Reicks View Farms Grain Bids
Foodsmart Jonesboro Ar Weekly Ad
Worthington Industries Red Jacket
3 Ways to Format a Computer - wikiHow
Osrs Important Letter
Ridge Culver Wegmans Pharmacy
Average weekly earnings in Great Britain
Sitting Human Silhouette Demonologist
Rocketpult Infinite Fuel
Does Iherb Accept Ebt
Tal 3L Zeus Replacement Lid
Merge Dragons Totem Grid
Cheetah Pitbull For Sale
Sabrina Scharf Net Worth
Complete List of Orange County Cities + Map (2024) — Orange County Insiders | Tips for locals & visitors
Jetblue 1919
Santa Clara County prepares for possible ‘tripledemic,’ with mask mandates for health care settings next month
Thotsbook Com
Craigslist Com St Cloud Mn
How To Customise Mii QR Codes in Tomodachi Life?
Paperlessemployee/Dollartree
Pas Bcbs Prefix
Underground Weather Tropical
Edict Of Force Poe
Glowforge Forum
Psalm 46 New International Version
Asisn Massage Near Me
E. 81 St. Deli Menu
Latest Posts
Article information

Author: Lidia Grady

Last Updated:

Views: 5834

Rating: 4.4 / 5 (45 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Lidia Grady

Birthday: 1992-01-22

Address: Suite 493 356 Dale Fall, New Wanda, RI 52485

Phone: +29914464387516

Job: Customer Engineer

Hobby: Cryptography, Writing, Dowsing, Stand-up comedy, Calligraphy, Web surfing, Ghost hunting

Introduction: My name is Lidia Grady, I am a thankful, fine, glamorous, lucky, lively, pleasant, shiny person who loves writing and wants to share my knowledge and understanding with you.