How does a blockchain transaction work?
|— Even if you’re familiar with crypto, you might still be unsure of exactly how a blockchain transaction works.|
— Blockchain is a distributed ledger that is kept running by various parties, such as nodes and miners, all of whom have an incentive to act.
— Factors such as transaction size, timing, block size and network usage all affect how your transaction will take place. Understanding the mechanics of that system will help you navigate your future transactions.
— Here we explain – how does a blockchain transaction work?
How does a blockchain transaction work? It’s a good question right?! Even for crypto pro’s, this can be tricky to grasp, so here’s your guide to the process.
Nodes, miners, protocols, mempools… are you confused yet? We get it, starting your crypto journey can be quite overwhelming. Whether you are a complete beginner, crypto curious, or have some basic understanding of how things work, it is hard to know where to start and can often feel like a foreign language, but if you are eager to learn more you have come to the right place. Just like learning a new language, once you grasp the key vocabulary the rest just falls into place. So let’s take a look at the jargon surrounding the transaction process, how it breaks down and what that means for you and me.
Quick Refresh: What is the Blockchain?
At its base, blockchain is just a massive, automated, decentralised ledger (or database). The primary purpose of crypto is to create a digital currency allowing peer-to-peer (P2P) transactions without any third-party involvement. The blockchain is for the secure transfer of items like money, property, contracts, and much more without requiring a third-party intermediary like a bank or government. You can find out more in our Ledger Academy article Blockchain Basics.
What is a transaction on the blockchain?
A transaction is a transfer of value on the blockchain. In very simple terms, a transaction is when one person gives a designated amount of cryptocurrency they own to another person.
To perform transactions on the blockchain, you need a wallet, a program linked with the blockchain to which only you have access, that keeps track of the crypto you own and allows you to transact with it. Each wallet is protected by a special cryptographic method that uses a unique pair of distinct but connected keys: a private and a public key.
A public key, also known as the address, is a series of letters and numbers that a user must share in order to receive funds. In contrast, a private key must be kept secret, much like your bank card pin number, as it authorizes the spending of any funds received by the associated public key.
With their wallet, a user (whoever has the private key) can authorize or sign transactions and thereby transfer value to a new owner. The transaction is then broadcast to the network to be included in the blockchain.
Let’s explore an example…
Alice wants to send 2 coins to Bob.
Unlike with traditional transactions, neither trust nor a contract is needed. Would you transact directly with a stranger online? Probably not. In regular transactions you either need to now and trust the person you’re transacting with (and even then there’s a risk) or else you need to use a contract to enforce the terms of your exchange, which comes with its own problems because it costs money to do that admin and – you guessed it – you need a third party to write and enforce it. Blockchain technology is revolutionary because it offers us a third option which is secure, quick, and cheap, and doesn’t involve another party.
OK – so how does it work?
We can think of a transaction as having three main parts:
- The input: Alice’s private coin address, where she is currently holding the coins she wants to spend.
- The output: Bob’s public key or coin address.
- Amounts: the amount of coins Alice wants to spend.
For Alice to send the 2 coins to Bob, she signs a message with the transaction details using her private key. The message contains the input, output, and amount to be sent. The transaction is then broadcast to the network saying the amount of coins in her account should go down by 2, and the amount in Bob’s account should increase by 2. Each computer in the network will receive the message and apply the requested transaction to its copy of the ledger, updating the account balances.
To keep track of the amount of crypto currency each of us owns, each blockchain uses a ledger, a digital file that tracks all the transactions. The ledger file is not stored in a central entity server, like a bank, or in a single data centre. It is distributed across the world via a network of private computers that are both storing data and executing computations. Each of these computers is on the blockchain network and has a copy of the ledger file meaning you can make your transactions without the need for a third party in a fast and secure way.
Seems simple enough right? But how do we know it’s secure? For that, we will have to look a little closer.
Breaking down a Transaction Step by Step
Before we dive into the details of a transaction, let’s start by introducing the characters making the process happen.
First, we have the users – that’s people like you and me, who are wanting to use the mechanics of the blockchain to make a transaction. But in a system that has no central structure, who makes that happen?
This is where miners come in. We know that blockchain is a trustless system – one that allows individuals to know their transaction will be honoured correctly without a central body overseeing it. Miners make this possible by verifiying incoming transction blocks – batches of requested transactions that are waiting (in the mempool, the stage between request and being added to the blockchain) to be confirmed. Doing so correctly means a reward for the miner/miners, which is the incentive that keeps the system running. Ever wondered why we pay gas fees? Here’s your answer: they compensate for the energy used in the process of mining transactions, and go toward the block reward for miners.
And finally, we have the nodes. Anyone can be a node – even you or me. Nodes keep the whole system safe and secure by validating the transaction blocks sent by the miners before they are added to the blockchain. They do so by checking the incoming information with the blockchain’s transaction history, to ensure everything matches. The network nodes – scattered across the planet – then collectively reach a consensus that new transactions are valid, before adding them to the blockchain.
The process of a transaction can be broken down into six steps:
- Someone requests a transaction. The transaction could involve cryptocurrency, contracts, records, or other information.
- Transaction is broadcast to all P2P participation computers in the specific blockchain network. These are called Nodes. All transactions are published to the Mem-pool or memory pool, where they are considered ‘pending’. Gas fees are paid by users as part of the transaction to compensate for the computing energy required to process and validate transactions on the blockchain.
- Miners verify the transaction. Every computer in the network checks the transaction against some validation rules that are set by the creators of the specific blockchain network.
- Validated transactions are stored into a block and are sealed with a lock referred to as the Hash.
- New block is added to the existing Blockchain. This block becomes part of the blockchain when other computers in the network validate if the lock on the block is correct.
- The transaction is complete. Now the transaction is part of the blockchain and cannot be altered in any way.
Different Ways Networks Reach an Agreement
One of the challenges with creating a crypto network is how to validate the transactions, without the need for a centralised body and for that you need to have people, lots of people! And people need to have an incentive, which is usually some native currency, they need to make a significant effort to prove they are willing to attest the validity of a transaction.
Currently there are 2 options to validate Proof-of-Work (PoW) where what you put at stake is the energy consumption and computing power into solving complex mathematical equations. Miners get the rewards when they are the first to solve the equation, and so it’s essentially a race between miners.
In the Proof-of-Stake (PoS) model, stakers, the PoS equivalent of miners, lock up funds in a smart contract. Every time a new block is needed by the network, an algorithm grants a specific staker the opportunity to publish the next block. The algorithm selects the staker via lottery, depending on each staker’s percentage of total staked funds.
Bitcoin uses a PoW consensus, but we are seeing a rise in PoS as an alternative consensus mechanism developed and used by a few alternative cryptocurrencies like Tezos and Cosmos. Ethereum is also transitioning from PoW to PoS. PoS was invented to eliminate the massive energy cost while bringing faster transaction speeds, better scalability, and reduced energy consumption to the network.
The Bus Station Analogy
Understanding block times, mempool size, and pending transactions are key to understanding not only how the blockchains work but for comparing different chains. It can be technical, but the bus station analogy can help us to visualize it.
Imagine a bus station and each bus represents a block that is going to be included on the blockchain and each person represents a transaction that is going to be sent to the blockchain. Some people are moving faster than others and some people are bigger than others. The people that are moving faster are transactions that are paying a higher fee, so a faster-moving person equals a higher fee, a bigger person represents a larger transaction.
Each bus can only hold a certain amount of people (1MB of information). Since space is limited, a limited number of transactions can be included in each bus or block. So each person buys a ticket whose price corresponds to their size and speed – the ticket officer is the network nodes. They take note of all this information and send each person to the waiting area.
The bus driver (miners) receives both a block subsidy (newly minted coin) and transaction fees (gas fees) for ordering people onto the bus. This means they are incentivized to prioritize the person or transaction with the highest fees. During times of high network congestion, where a large number of users want to transact or get on the bus, the transactions with the highest fees are more likely to be included in the next bus/ block.
There is a great visual tool which uses cartoon-like bus stop graphics to depict the differences between Ethereum, Bitcoin, and Bitcoin Cash blockchains in a simple, fun, and intuitive way.
Now you know exactly how it works you can get involved yourself – you can even operate your own node!
The beauty of blockchain is that it is completely decentralized way of transacting – this means you have freedom to move your money and data as you like, without sharing your details with a central entity, and without barriers to entry. So decentralization is effectively creating a fairer balance of power between big central entities and regular people like you and me, and operating as a node within this system lets you contribute to this change. It’s about much more than money – and anyone can be a part of it.
Konwledge is power.
Trust yourself and keep on learning. Understanding the mechanics of blockchain gives you a major edge when it comes to navigating the space. So dive in to our School of Block episode all about the details.