What is a transaction in a blockchain?

A blockchain, like a database, can be used to store data. However, the structure in which the data is stored is different. In a database, data is stored in the form of tables. However, in a blockchain, data is stored in blocks (chunks of data) that are chained together.

Structure of a blockchain

What is a block?

A chunk of data (or a few transactions) is grouped to form a block in a blockchain.

These blocks are linked together by adding previous blocks' hashes to the next block.

Chaining of blocks in a blockchain

What is a transaction?

A transaction is a chunk of data stored on the blockchain. It can contain different forms of data depending on the purpose for which the blockchain is being used. A few types of data that can be stored in a transaction are as follows:

  • Votes: If we use the blockchain for electronic voting.

  • Property documents: If we use the blockchain for keeping property records.

  • Smart contracts: If we use the blockchain for running our code.

  • Local currency transactions (Bitcoin): If we use the blockchain for cryptocurrency.

Examples

The formats of Bitcoin and Ethereum transactions are as follows:

  1. Bitcoin transaction format

Every Bitcoin transaction has some inputs and outputs (that are locked to the hash of the owner's public key) as shown below.

A Bitcoin transaction

Every input points to a UTXO previously created in a transaction's output. This is done by using the ID of that previous transaction (where that UTXO was created), and as a transaction has an array of outputs, we need to provide an index of the output we need to use.

A unique index identifies every output, and it is locked to the hash of the owner's public key (contained in the ScriptPubKey). To unlock an output, we need to provide a valid public key and a signature to authenticate ourselves; only then will we be allowed to spend those Bitcoins.

  1. Ethereum transaction format

Every Ethereum transaction has fields such as nonce, recipient address, the number of EthersIt is the local currency of the Ethereum blockchain. to be transferred, and so on.

How does a transaction become a part of the blockchain?

A transaction is verified and added to the blockchain in the following steps:

  1. A user generates a transaction and sends it to all the nodes on the network.

  2. Nodes verify this transaction and add it to their candidate blocksIt's block that a miner tries to block..

  3. Nodes then broadcast their candidate blocks to the entire network.

  4. A consensus is held, and every node verifies all the transactions in the candidate block before adding it to their journalLocal view of the blockchain for that node..

  5. When most nodes add this block to their journals, this transaction is finally verified and becomes part of that blockchain.

Initial state of the blockchain
1 of 5

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved