Reality
If anyone says they have 5
bitcoins in their wallet they actually mean, they have unspent transaction
outputs (utxo) which, clubbed together sum up to 5 bitcoins. And to have utxo
they should first have a bitcoin address which consists version, public key
hash followed by check sum, and bitcoin address could be shared by QR Code.
Begin Transaction
When buyer pays 3 bitcoins to
seller it means, he has transferred 3 bitcoins to seller’s bitcoin address i.e.
he has initiated a transaction which converts his existing utxo(specified by
txid) to seller’s address (specified either by P2PKH or P2SH) along with
buyer’s signature(specified by buyer’s full public key) and pub key script(instructions,
that allows anyone to spend amount who control buyer’s private key).
Spend Transaction
Now if the seller who
received 3 bitcoins would like to transfer them, he adds prev-txid, vout,
script sig to the Input, where prev-txid is txid of buyer to seller, vout is
output index of buyer to seller, script sigs which is collection of data
parameters (receivers public key, signature) that satisfied conditions placed
by pub key script of buyer to seller.
With the above input, amount
and new txid along with new pub script will be send to the new indented bitcoin
address and transaction is uploaded to the network.
Transaction validation or Mining
Once uploaded the transaction has to be validated and then will be added to the block chain(which provides bitcoins public
ledger and is an ordered and time stamped record of transactions). A transaction
that is added to the network will be validated by bitcoin miners by proof of
work which avoids double spending of bitcoins.
For validation miners check
two things in a transaction, first that you are actual recipients of utxo, Second
that you have not already used those utxo. If everything is proper the miner
will add transaction to his personal list of valid transactions, and every few
minutes one miner will be given chance to add their personal list i.e. a block
to the official block chain.
A block will be added to the
official block chain if miner transactions are valid and miner correctly
guessed a random number called nonce. So miner adds previous block signature,
and the transaction.
Mining Rewards
Not just that miners get rewarded in two ways
viz. few bitcoins as reward, small transaction fee from the person who has
initiated the transaction. So to gain such rewards many miners compete to add transaction to
network, bitcoin rules ask miners to generate a difficult hash (like one that
starts with certain number of zeros), which involves a combination of inputs
one of which is a random number called ‘nonce’ that miners will have to guess,
and miners with powerful computers can make such guess faster, so miners
usually invest in high performance computing.
Multi Ouput transactions
A single transaction can
create multiple outputs, as would be the case when sending to multiple
addresses, but each output of a particular transaction can only be used as an
input once in the block chain. It means if you have utxo of 1BTC, 1.5BTC and if
you need to pay 0.5BTC to seller then, you have to sign utxo of 1BTC to seller
with output of 0.5 BTC to seller and change of 0.5BTC to your own bitcoin
address.
Any bitcoin transaction can
have multiple inputs (n1btc, n2btc, n3btc) and multiple outputs (r1btc, r2btc)
with condition r1+r2=n1+n2+n3, but to be
noted that n1btc cannot be divided directly to be used in two transactions (but
has to generated as new utxo with (n-k)btc).Hence either of n1,n2,n3 btc cannot be reused in another
transaction avoiding double spending.

No comments:
Post a Comment