Blockchain Byte - Week 19 : Crypto Payments

Blockchain Byte - Week 19 : Crypto Payments
Photo by Kanchanara / Unsplash

Table of Contents

  1. Recap
  2. Wallet
  3. Transaction Type - Input / Output
  4. UTXO - Unspent Transaction Output
  5. Digital Signature
  6. Scripts - Lock / Unlock


To recap, last week we explained payments in fiat currency through banks & Financial Institutions. We are aware of payment rails in traditional payments like Swift, Automated Clearing Houses (ACH), etc. However, before we get into payments in Blockchain which can be a new payment rail, we have to understand the below aspects during a payment transaction.

  1. Wallets
  2. Private & Public Keys
  3. Addresses &
  4. Digital Signatures

Let us explore each of them this week :


A wallet:

a. Controls access to a user's cryptocurrency

b. Manages keys and addresses

c. Signs transactions

d. Tracks balances of cryptocurrency

The below image is that of a wallet:


Photo by olieman.eth on Unsplash

Let us see how a wallet does all of the above and more!!

A wallet has a public & private key and interacts with the Blockchain. Let us assume that the "Sender" wants to transfer crypto currency (e.g., Bitcoin) to "Beneficiary". For that the Sender needs to "own" some crypto already. Let us assume the sender owns 100 BTC.

We know that wallets control access to a user's cryptocurrency & the only way users can manage their cryptocurrency is through a wallet. This means the user's wallet accesses the "balance" of cryptocurrency in the Blockchain.

This is like our phones or browsers accessing the Bank system where the funds actually reside.

Let us analogize with traditional banking. When we say we have "balance" in our account , what does that mean? Simple - We put in funds & take out some (or don't), the resulting amount is the balance. Let us see it from entry point of view.

Assume we are opening an account for the first time and we deposit cash into that account. The entry that is passed in the bank's books along with the customer ledger account is as below:

Entry 1.jpg

Thus the customer's account has a credit balance of USD 100.

If USD 50 is withdrawn from an ATM, the below entry will be passed in the bank's book

Entry 2.jpg

Now, the net balance in the customer account is

USD 100 - USD 50 = USD 50.

This balance is available for the customer to use, spend or transfer for any purpose (Keep this in mind as we read forward!!).

So, a balance in an account arises out of transactions and if

  1. Inflows into the account is > outflows from the account, balance is positive
  2. Inflows into the account = outflows from the account, balance is zero &
  3. Outflows from the account > inflows into the account, the account is said to be overdrawn (if allowed by the bank within set limits).

Transaction Type - Input / Output

Similarly, in a Blockchain, when we say Sender owns 100 BTC, it means there were transactions - inflows and outflows which caused the net balance to be 100 BTC.

The inflow (credit) transaction is called a TRANSACTION OUTPUT.

Transaction Outputs are indivisible amounts of cryptocurrency recorded on a blockchain.

The outflow (debit) transactions is called a TRANSACTION INPUT.

Transaction Inputs are transactions which spend the cryptocurrency paid to a previous output.

(Source of definitions : here)

The below diagram makes it more clear. We assume the balance of 100 BTC came from two transactions - an inflow of 300 BTC & outflow of 200 BTC meaning

Transaction Output = Inflow of 300 BTC

Transaction Input = Output of 200 BTC

Entry 3.jpg

UTXO (Unspent Transaction Output)

The closing balance of 100 BTC is called an unspent transaction output or UTXO. That means this balance is unspent and available for spending in the future (just like closing balance in your bank account).

Here, we assumed there was only one transaction output & input transaction. However, in reality, there will be multiple transactions linked to one address at any point in time just like there are multiple transactions in our accounts.

But in a bank account, all the transactions are in one account and there is one closing balance in that account. In a Blockchain, each transaction creates a separate UTXO which are spread across different blocks. (We will explain blocks later!!).

Thus, there are multiple UTXOs attached to one address. When we refer to Sender's Bitcoin "balance", it means the sum of all UTXOs that a user's wallet can access and spend and which may be scattered across multiple transactions and different blocks. The below diagram makes it more clear.

Entry 4.jpg

But, there is one question - In a bank account, there is a single account and we "connect" or sign into that account using a password. In crypto world, how does the crypto "owner" connect to his balance (UTXO) or balances (multiple UTXOs) which is/are in the Blockchain? We answered this.. through a wallet.

Now, how does the wallet know which UTXO to connect to from where the funds can be used later? This is where digital signature comes in handy.

Digital Signature

To recap, a digital signature consists of two algorithms :

  1. A SIGNING ALGORITHM that, given a private key & a transaction, produces a signature &
  2. A SIGNATURE VERIFYING ALGORITHM, that allows anyone to verify the signature, given the message & a public key (corresponding to the private key used in the signing algorithm)

In simple terms, Private Key + Digital imprint of Transaction = Digital Signature

which means a private key can be applied to the transaction to produce a digital signature. This signature can only be produced by someone with the knowledge of the private key.

Digital Signature.jpg

Thus, Sender's wallet is "locked" to the UTXO (or multiple UTXOs) of 100 BTC through digital signature from his / her wallet. The private key plus the digital imprint of the transaction can be accessed only from Sender's wallet. Thus this is irrefutable proof that the Sender "owns" the funds.

Now, these funds are "locked" to the wallet and if these funds are to be released, they need to be "unlocked". Now, how does the funds get unlocked & released to be spent? In the case of online banking, funds can be sent only through

  1. Input of correct password or OTP &
  2. Input of valid beneficiary.

Scripts - Lock & Unlock

In crypto world, there are "scripts" which does this activity. In the case of bitcoin, each bitcoin transaction involves at least one

a. Locking Script &

b. Unlocking Script

A Locking Script is a code which says what conditions must be satisfied to access the UTXO for future spending. (E.g., a condition can be - only owner with a particular private key can "unlock" this transaction)

An unlocking Script is a code which satisfies those conditions and allows the funds to be "unlocked" for spending.

So, to transfer funds, the transaction inputs point to the relevant UTXO and then proves ownership through the unlocking script.

Now, it needs to be understood that a UTXO can only be "spent" or "consumed" in its entirety and not piecemeal. For example, if you have 100 USD and you need to spend 80 USD, you will give 100 USD and receive 20 USD change back. It is the same in Bitcoin blockchain but not entirely.

Let us assume Sender wants to send 50 BTC to Beneficiary. Sender's wallet will scan the blockchain for UTXOs linked to that wallet which are available for spending. It then comes across UTXO for 100 BTC. It will create two transaction inputs from the UTXO -

a. One transaction of 50 BTC which will go to Beneficiary wallet

b. Second transaction of 50 BTC which will go back to Sender wallet

Thus, the UTXO of 100 BTC is extinguished and two other transactions take its place where 50 BTC "moves forward " to Beneficiary wallet as a UTXO which is linked to Beneficiary wallet and 50 BTC moves back to Sender's wallet as a new UTXO meaning they each have " new balance" of 50 BTC to spend in the future.

When the BTC moves from sender to beneficiary, the beneficiary's wallet "ties" the 50 BTC UTXO to itself through it's digital signature and then the UTXO is linked to this wallet.

The below visualization makes it more clear:

This is at a very high level how value "moves" from one address to another in the Bitcoin Blockchain.

What happens next? Who verifies these transactions and how are these transactions verified?