Table of contents
Lesson 8
How does a blockchain transaction work?
How does a blockchain transaction work?

7 min reading time

Updated

How does a blockchain transaction work?

A blockchain transaction consists of three components: a sender, a receiver, and a quantity. The sender and receiver do not necessarily have to be two different people. It is also possible to perform a blockchain transaction to transfer cryptocurrency from one place to another, just as it is possible to move fiat currency from a savings account to a current account. 

Wallets and addresses

Unlike a wallet with fiat money, a crypto wallet does not actually contain crypto coins. A wallet stores the private and public keys, but also all transactions performed to and from the wallet address. With the overview of all executed transactions, a balance can be drawn up to calculate the total number of crypto coins in a wallet. 

Public and private keys

It’s okay if someone else knows your public key. Moreover, it is only possible for other people to send crypto to the wallet address resulting from the public key. It is not possible for other people to remove crypto if they are in possession of the public key.

A private key is also linked to a public key. A private key consists of a sequence of 64 numbers and letters. As the name suggests, it is important not to make a private key public. A private key is a kind of password that gives permission to send a certain amount of cryptocurrency from a specific wallet to a new address. 

Wallet address

A crypto wallet address is the hash version of the public key. This address can be compared with the IBAN number of a bank account. Once someone wants to send cryptocurrencies, they enter the wallet address to indicate where the cryptocurrencies should go.

This means that a wallet address is not the same as a public key, as is often thought. Each public key is 256 bits long. The resulting hash is 160 bits long and case sensitive. 

Transaction

A blockchain transaction consists of 3 components: a sender, a receiver and a quantity. It is possible that the sender and the receiver are the same person, i.e. when someone wants to move cryptocurrencies from one wallet to another wallet. It is therefore better to speak of input (sender) and output (receiver). 

Input and output

Calling a sender and receiver ‘input and output’ is a simplification of reality. Indeed, an input contains all information from previous transactions to the sender. An input is therefore based on previous outputs. Depending on the amount, multiple inputs may be required. This becomes clear with an example: 

Daan wants to send 2 BTC to Lisa

The input of this transaction is based on the output of cryptocurrency previously sent to Daan. In the past, Daan received 1 BTC from Floor and 1 BTC from Marijn. To now send 2 BTC to Lisa, two inputs are needed: one input from Floor’s 1 BTC and one input from Marijn’s 1 BTC. 

Daan wants to send 1 BTC to Lisa

If Daan does not want to send 2 but only 1 BTC to Lisa, only one input is needed for the transaction. It is possible to use the input of the 1 BTC of Floor or the input of the 1 BTC of Marijn. 

In addition to multiple inputs, multiple outputs may also be required. The above example then becomes:

Daan wants to send 2 BTC to Lisa

Daan has a total of 2 BTC (1 BTC from Floor and 1 BTC from Marijn). He wants to send these 2 BTC to Lisa. The output of this transaction is 2 BTC to Lisa’s public key. 

Daan wants to send 1 BTC to Lisa

Daan has a total of 2 BTC and wants to send 1 BTC of that to Lisa. There are two outputs associated with these transactions. The first output is 1 BTC to Lisa’s public key. The second output is the change that remains. Daan has 2 BTC of which he sends 1 BTC to Lisa. So he still has 1 BTC change left that is sent back to his wallet. This is the second output of this transaction. 

Digital signature

Carrying out a transaction is done via a wallet in the cryptocurrency software. The software asks you to provide the recipient’s public key and specify the amount. It is therefore not necessary to enter the inputs and outputs yourself, the software does this itself behind the scenes. 

A password is required to confirm the transaction: the private key of the wallet from which the cryptocurrency is sent. The software creates a digital signature from this data, the so-called ‘signature’. A digital signature is therefore based on the private key of a particular wallet, but does not contain it literally. Thus, the private key is not made public and remains secret. The digital signature is then sent to the network for validation.  

Verification

Each transaction is sent to the network for verification. The network consists of nodes and miners. The miners scan the entire network to check whether a person who wants to send some cryptocurrency actually owns it. The miners also check whether the cryptocurrency to be sent has not yet been sent to someone else, a so-called ‘double spend’. 

The network checks this information on the basis of the transmitted digital signature and the public key. If the digital signature was created with the private key that matches the public key, the transaction is valid. Thanks to the digital signature, the network can therefore verify transactions without having to know what the actual private key is. 

After the transaction has been validated by the miners, the transaction is recorded in a block. Each block contains information from approximately 500 transactions. All the blocks together form the blockchain. Each miner stores a copy of the entire blockchain. 

Each block also contains information from the recorded transactions of the previous block. If a transaction in a previous block is manipulated, the current block must also be modified. Modifying blocks is a difficult task because the blockchain just keeps on going. By the time a previous block has been modified, a new block has probably already been created which in turn needs to be modified, and so on. This essentially means that transactions can almost never be changed or undone. 

What are transaction costs?

A blockchain transaction is not free. When someone wants to send cryptocurrency, transaction costs will also have to be paid. Transaction costs are costs that have to be paid to have a transaction checked and recorded in the blockchain. The transaction costs also serve as a reward for the miner who performs the check. These costs range from a few cents to €100. The reason for this variation is that transaction costs depend on the size of the transaction and supply and demand of the network.

Transaction size

The size of the transaction mainly depends on the amount of cryptocurrency in the transaction. Sending 10 BTC will most likely require multiple inputs while sending 1 BTC is more likely to be possible with a single input. The more inputs, the more space the transaction takes up in a block. This means that a miner can record a smaller number of transactions in the same block and therefore gets less reward. Miners will primarily choose to validate small transactions with high transaction costs in order to maximize their reward from transaction costs. By setting the transaction costs of a large transaction higher, miners are no longer disadvantaged if they choose a small number of large transactions instead of a large number of small transactions.   

Supply and demand

Some transactions take longer to be validated. This is because of the limited space in a block, this also depends on the blockchain. Miners select only those transactions for which the transaction costs are high enough, because the transaction costs serve as a reward for the miner who performs the validation. The higher the transaction costs, the more motivated a miner will be to validate that particular transaction. Transaction costs thus respond to supply and demand on the network. The busier the network, the higher the transaction costs will be. 

Several wallets allow you to determine the transaction costs yourself. If it is not necessary to execute the transaction immediately, the user can lower the transaction costs so that the transaction is picked up by a miner later when the network is less busy. This also works the other way around: if a transaction has to be executed immediately, the user can enter higher transaction costs so that miners are more motivated to validate that transaction first. This will result in a faster settlement. 

Summary

A wallet stores the public and private keys of a user, but also the transaction history of the wallet. Users send their cryptocurrency to the wallet address when making a transaction. The wallet address is derived from the public key by means of a hash. This means that the public key and the wallet address are not the same. A blockchain transaction consists of three components: the input, the output and an amount. 

Cryptocurrency software converts the amount and public key to which the cryptocurrency must be sent into a digital ‘signature’. Miners verify the transaction based on the digital signature. Once the transaction has been checked and validated by the miners, it is recorded in a block.

Each transaction has a transaction fee and this transaction fee is paid as a reward to the miner who performs the validation. Transaction fees depend on supply and demand on the network and on the size of the transaction.