19 votes
Accepted

How do virtual size, stripped size and raw size compare between legacy address formats and native segwit?

Let's compare a 2-input and 2-output transaction for single-sig output types. I'll refer to the byte length of the transaction as "raw size" , the transaction without its witness data as &...
  • 68.7k
15 votes

What is Bitcoin locking and unlocking script?

There are quite a lot of things going on there, so let's break it down bit by bit. Transaction structure A transaction can be seen as a collection of inputs and outputs. Inputs refer to previously ...
  • 2,882
12 votes

What is the maximum number of inputs/outputs a transaction can have?

The total size of the transaction must be less than 100,000 bytes or it will not be relayed across the network or included in blocks. There COULD be a miner that is mining >100K transactions, but I ...
12 votes
Accepted

multiple input and output addresses in bitcoin transactions

why some of transactions have one input and one output? A bitcoin transaction can have many inputs and many outputs. Bitcoin has a transaction oriented logic, where amounts are transferred from ...
  • 5,076
10 votes
Accepted

How big is the input of a P2PKH transaction?

The first number does not include the prevout, sequence number, or the length byte for the scriptSig. It also uses 65 bytes for the public key (which is correct if it is uncompressed, but compressed ...
10 votes
Accepted

Why are transaction input and output indices called `vin` and `vout`?

The original Satoshi codebase used a programming style called "Hungarian notation", where variable names are prefixed with letters that indicate the data type they contain. v in particular ...
8 votes
Accepted

How do transaction costs compare between Bech32 addresses and legacy Bitcoin addresses?

Transfer from Legacy ⟶ SegWit: pay full fee (doesn't benefit from SegWit discount) Transfer from SegWit ⟶ Legacy or SegWit: discounted. Note: SegWit addresses can be Bech32 bc1... or they can be ...
7 votes
Accepted

Maximum number of inputs per transaction

No, the number that can be represented by the varint has no effect on the maximum number of inputs. That number is far too large. Rather the maximum number of inputs is constrained by the block size. ...
  • 65.7k
7 votes
Accepted

What are the sizes of single-sig and 2-of-3 multisig taproot inputs?

Taproot generally has two ways of spending. The default way is to spend the output using the key path: pay-to-taproot then behaves like a p2pk output except that it is using a schnorr signature and ...
  • 68.7k
7 votes
Accepted

Does the coinbase transaction have inputs?

Coinbase transactions must: Have exactly 1 input. That input must have prevout hash 0000...0000, and index 0xFFFFFFFF (an output which isn't actually spent). The input's scriptSig must be between 2 ...
6 votes

SegWit and previous hash: txid or wtxid, or either?

Inside transaction inputs, you have to refer to previous transactions using the txid. Allowing a wtxid there would be (1) a hard fork and (2) defeating the purpose, as it'd make transactions malleable ...
6 votes
Accepted

How to retrieve the from and to wallet addresses of a transaction?

Which part / field of the input refers to the hash of the output? The outpoint contains a txid (32 bytes) and vout (4 bytes), which specify the output you're spending. This is not the sending ...
6 votes
Accepted

What are the standard formats of transaction outputs?

AFAIK there are 5 different standard non-SegWit transaction types, and 4 SegWit ones. Non-SegWit: Pay to public key (P2PK) PUSH (1 byte) + <compressed/uncompressed_pk> (33/65 bytes) + ...
  • 2,882
6 votes
Accepted

Can signature be re-used to cash out everything in the address?

When you sign the transaction with your private key, you include the hash of the entire transaction data as a message. This means the signature which is generated is specific to that transaction ...
  • 7,183
6 votes
Accepted

How can the segwit witness data be "off-chain"? What does it really mean?

No, that's not accurate. Witness data is on-chain, inputs have a similar byte length as before (they are just weighed differently), and the transaction throughput is increased because segwit is a ...
  • 68.7k
6 votes
Accepted

Segwit includes the input amount in the SignatureHash. What possible attack can this prevent?

Consider a transaction that has 2 inputs and 1 output. Let's say that the inputs are both 1 BTC and the output is 1.5 BTC. This would mean that the transaction pays a 0.5 BTC fee, which is ridiculous. ...
  • 65.7k
6 votes
Accepted

Why is the locktime set at transaction level while the sequence is set at input level?

See @RedGrittyBrick's answer for historical context for why there is a per-input nSequence field. The evolution since includes: nLockTime's meaning has been unchanged since the early days; it ...
5 votes

What order does Bitcoin Core place the inputs it spends in?

The inputs are chosen by the function SelectCoins() in CreateTransaction() and then added one by one (without shuffling) to the transaction. The order is defined by the coin selection (CWallet::...
5 votes

If I reuse the same address can a previously used transaction be reused?

Can somebody take the transaction tx0 I signed and publish it in order to spend the new coins with the old transaction? No. Firstly, the transaction inputs are already known to have been used. Any ...
5 votes
Accepted

What is the size and weight of a P2WPKH input?

TL;DR: A P2WPKH input should be conservatively estimated with 68.0 vbytes. Standard P2WPKH inputs generally weigh 67.75 or 68.0 vbytes, depending on whether the r-value in the signature is low or high....
  • 68.7k
4 votes

How to retrieve the from and to wallet addresses of a transaction?

The scriptPubKey contains the public key used to synthesize the public address. Here are two pedantic approaches, not using bitcoinj, applying bx commands to synthesize the public address of interest ...
  • 2,997
4 votes

What is the maximum number of inputs/outputs a transaction can have?

The economical way in your case would be to pay off (create as much outputs) as you can to decrease the fee cost. Some standard transaction with one proven input and one output is about 161 - 250 ...
  • 869
4 votes
Accepted

What is the point of including the scriptCode of the input in the transaction digest of segwit?

What problems could arise if the scriptCode of the input were not included in the digest? Almost certainly nothing. The reason for doing this is a very intentional design choice to limit the number ...
4 votes

What happens when two transactions send to the same address?

It works just fine. Bitcoin transactions can have multiple inputs and outputs; each input is a "pointer" to an output of a previous transaction (specifically, it consists of a transaction id and ...
4 votes

How come that there can be many transfers in a single Bitcoin transaction?

Ethereum is an account based system. It relies on the sender specifying the sequence of transactions to prevent double spending. The balance is associated with an address and when you spend from that ...
  • 68.7k
4 votes
Accepted

How to get address from CTxIn object

I suppose you are the same person who made this thread on bitcointalk: https://bitcointalk.org/index.php?topic=1969807.0 I'll answer you here too to help other people too. You are treating the ...
  • 65.7k
4 votes
Accepted

Submitted a raw tx that was already on the blockchain, to test it. I got 'missing inputs' instead of 'already exists'. Why?

Bitcoin Core has no idea which transactions already exist in the chain. It does not maintain a full index, because... it doesn't need to. In fact, when running in pruning mode, it doesn't even have ...
4 votes
Accepted

How are 'excessive' numbers of inputs and outputs handled in bitcoin transactions?

The number of inputs/outputs is encoded as a "var_int" or "variable length integer". Start by looking at the first byte. If it's 252 or less, then that's it, that's your number (like you've been ...
  • 11.6k
4 votes
Accepted

How to read a transaction from a block? Who paid whom?

When you send a Bitcoin transaction, your wallet software will use one or more existing Unspent Transaction Outputs (UTXO) to fund the transaction. The transaction will then specify the new owners of ...
  • 68.7k
4 votes
Accepted

How does fee split between senders in a transaction?

There is no real concept of sender identities, as far as the blockchain is concerned. The fee split is entirely determined by the change output values, which are entirely determined by the signers of ...
  • 16.7k

Only top scored, non community-wiki answers of a minimum length are eligible