How Fund Transfer is Done in Bitcoin

1. Overview

This write-up is to show how Bitcoin wallets tranfer bitcoins. We will first examine how wallet works and get some idea on transaction fee. Finally we will take a look on the transaction and how it is stored in the distributed ledger (Bitcoin blockchain).

Bitcoin Testnet is being used in this setup, and Bitcoin-Qt is installed as a node on Testnet. It comes with a user interface. Also bitcoin-cli is used to access more detail in the transaction and block.

There is a sister article “How Transaction is Done in IOTA”. Ideally open that file as well, and read both in parallel for a better comparison.

2. Setup

In this setup there are two computers, each of which is installed with bitcoin-qt a full node for Testnet. We designate them as Wallet A and Wallet B. Some addresses are predefined in Wallet A and only keep one address on Wallet B. Note that one can generate as many as Bitcoin addresses in a wallet at one’s wish.

3. Fund Transfer

3.1 Before Fund Transfer

Fund (3.89681437 BTC) is deposited on Wallet A and we keep empty on Wallet B. Here is what we see in both wallets.

If we go more detail inside Wallet A, we see how this amount of bitcoins is composed.

We see in Wallet A, there are two addresses, each of which has two entries of balance. Total there are four such entries. Summing all these four records, it is the amount seen in Wallet A.

We keep Wallet B empty.

Here is the summary of both wallets currently.

3.2 Fund Transfer

On Wallet A, we input Wallet B’s address and transfer 2 BTC.

Note that there is an option “Subtract fee from amount”. If this box is not checked, the transaction fee is paid on top of 2 BTC. As a result, Wallet B will receive 2 BTC, while Wallet A spends more than 2 BTC. We will see this later.

3.3 Transaction Pending for Confirmation

After sending the amount on Wallet A, we see some change on both wallets.

This is Wallet A after sending the fund.

We observe in Wallet A,

  • A new transaction is recorded (first entry in Recent transactions) showing that 2.00001317 BTC is sent.
  • The balance immediately becomes 1.89680120 BTC, reflecting the reduction from the amount 2.00001317 BTC.

This is Wallet B.

We observe in Wallet B,

  • A new transaction is recorded (first entry in Recent transactions) showing that 2.00000000 BTC is received. Note that the amount is in square bracket and not the same as other previous transactions. It is because this transaction is not yet confirmed, that is, pending.
  • The balance immediately becomes 2.00000000 BTC, but is not yet available. This amount is still pending for confirmation.

3.4 Transaction Confirmed

After a while, this transaction is confirmed. Nothing happens on Wallet A. In Wallet B, we see that amount of bitcoins becomes available.

4. Transaction in Detail

4.1 Unspent Records in Wallets

As seen previous, we see four entries in Wallet A and no entry in Wallet B before we transfer fund.

After we send the fund, we see two stages: before and after confirmation.

Before Confirmation

Two entries remain in Wallet A

We see no records in Wallet B yet.

So here is the summary before confirmation.

After Confirmation

A new entry is seen in Wallet A. And it comes with a new address. This address is automatically generated by Wallet A.

In Wallet B, the transaction is there.

And we can see the txid of both new transactions in both wallets are the same. They are referring to the same transaction (we will see this very soon).

So here is the summary after confirmation.

4.2 How to Fund this Transaction

It is quite obvious that in order to fund the transfer of 2 BTC, Wallet A selects the available inputs and locates some with total more than 2 BTC. They are the missing inputs before confirmation.

With these two entries together, 2 BTC is paid to Wallet B, and the change is kept as a new entry.

And when we compare the change kept in Wallet A, we see the difference. It is the transaction fee paid to miner who successfully adds the block to Bitcoin blockchain.

4.3 Inside the Transaction

When Wallet A sends some bitcoins, a transaction is sent out to Bitcoin network. We now take a look what is inside the transaction from both wallets, and see it from Bitcoin Testnet.

From Wallet A,

And from Wallet B,

Some observations

  • Majority of information are identical, as we are referring to the same transaction (same txid).
  • Transaction fee is only seen in Wallet A, and the amount matches our calculation above.
  • This transaction will be confirmed and placed into a block by miner. And from here we see some block information: blockhash, blockindex and blocktime. We will cover block later.
  • Inside the category of detail, Wallet A is ‘send’ and Wallet B is ‘receive’.

This transaction is already in Bitcoin Testnet, and all transactions are publicly visible. We can use the txid to locate this transaction in any Bitcoin Explorer (Testnet). Here is an example.

This is the full picture of the transaction. The left-side is the input, where the transaction is funded. The right-side is the output, one to Wallet B and one back to Wallet A. That amount has a (U) beside, meaning that it is an unspent transaction output, and can be used later as input of a new transaction.

4.4 Where is The Transaction Kept?

Bitcoin network is a distributed ledger using blockchain technology. The transactions from all users are grouped into block, and the block is then added to the chain.

From Section 4.3, we have the blockhash from the transaction above (blockhash: 000000 …. 67e03d). We can use command line to get more information about this block.

Some observations,

  • This blockhash, and other blockhash we can see, begins with a series of zero. It is the result of mining. Miner collects the unconfirmed transactions (like the one Wallet A sends to Wallet B), verifying them, and calculating the nonce such that the blockhash has a specific number of leading zeros.
  • The height can roughly seen as the block index (i.e., how many blocks from the block zero).
  • Inside tx, there are a group of transactions in this block. If we examine our previous transaction output, we know that the blockindex is 9. We see the transaction is in the index 9 inside tx (98651a …).
  • The previousblockhash is the blockhash of the previous block. This is how the chain is built: each block is referring to a previous block. This block is also a previousblockhash of another block.

Again we can see the same information public (truncated).

Here is the relationship between our transaction, the block, and the blockchain.

5 Summary

We have explored how fund is transferred between wallets in Bitcoin network, and what happens behind this transfer. We also touched very basic block structure in Bitcoin blockchain, and how the transaction is placed inside a block. A lot of detail is skipped, but this should be good enough for understanding more about Bitcoin.

Written by

Happy to share what I learn on blockchain. Visit http://www.ledgertech.biz/kcarticles.html for my works. or reach me on https://www.linkedin.com/in/ktam1/.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store