0

Some days ago, I write a program to extract output addresses and its value in tx messages of a sample bitcoin pcap. extracted addresses are all valid and we can find them in block explorers.

after that, just for testing, I send a specific value from one wallet to another wallet and capture all input/output packets during this transfer.

When I test my program with this sample traffic, some addresses and values are generated, one of those addresses was my own address and its value was the same value which I transferred, but some other addresses are generated which are all valid addresses and valid values but I don't know their value.

I guess that these values are UTXOs, but how I can sure about that? Also, I see same value and same address which i sent in my wallet, in multiple packets with different source and destination IP addresses. for example I send A bitcoin from one wallet to another one, and beside that B bitcoin sent to

1

2 Answers 2

2

When a Bitcoin transaction is created, unspent transaction outputs (UTXOs) are used in the inputs of the transaction. Your wallet will use as many UTXOs (and therefore create as many inputs) as necessary to achieve the value you're trying to send in your transaction.

UTXOs have to be spent completely, so most likely the total value achieved by the sum of the inputs will be greater than the amount you wanted to transfer. There's where change outputs come into play (the additional outputs you're getting). In order to avoid having to send more value than you wanted to the destination address (addr_dst), the difference between the sum of the inputs (vi) and the value to be sent (vo) is sent to a change address (addr_chng), i.e:

vo - fee is sent to addr_dst

vi - vo - fee is sent to addr_chng

That change address is usually owned by you.

2
  • Actually I think all vo is sent to addr_dst and fee just reduced from our input(vi), so if i send A bitcoin to my friend with a specific address, he receives all A bitcoin in his wallet.
    – Saeed
    Jun 2, 2019 at 4:55
  • Well, it depends on the implementation, but sure, it's also possible.
    – sr_gi
    Jun 2, 2019 at 15:02
0

Bitcoin transactions do not spend from addresses, and addresses do not have balances
Every transaction has one or more inputs and one or more outputs
An output is an address and an amount
An input is a reference pointer to the output it is spending - the reference is a unique identifier for a single output: txID and output number (eg. 0, 1, 2, 3)

An output which has not been spent is a coin
To spend a coin, create a transaction with an input which points to the coin

Bitcoin does not have partial spends
A coin can only be spent completely
A coin can only be spent once

I send a specific value from one wallet to another wallet

You spent one or more coins. The value of those coins was greater than the amount you needed to pay. You transaction has 2 outputs (new coins). One of the outputs is the address and amount you were sending. The other output is the difference between your input coins and the amount you were spending - referred to as "change". The change address is your address. The change coin belongs to you, to spend in a future transaction

* This explanation omits the transaction fee, for simplification. The other answer is more complete because it mentions fees

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.