Tech News, Tech & Coding · Free Online Tools

IT Question Answer
Back to Blockchain
How Does Blockchain Work?

How Does Blockchain Work?

BlockchainBy Muhammad Fareed
blockchain

Short answer: users sign transactions, the network checks them, a chosen node bundles them into a block, other nodes verify and accept the block through a consensus rule, and the block is linked to the chain by its hash. Each step makes cheating expensive.

Step-by-step life of a transaction

  1. Create: Sara wants to send 1 coin to Ali. Her wallet builds a transaction.
  2. Sign: the wallet signs it with Sara's private key. Anyone can verify the signature with her public key, but cannot forge it.
  3. Broadcast: the transaction is sent to nearby nodes, which pass it along.
  4. Validate: nodes check the signature and that Sara actually has enough balance and has not spent the coin already.
  5. Pool: valid transactions wait in a pool of pending transactions.
  6. Propose a block: a miner or validator groups pending transactions into a block.
  7. Consensus: the network agrees the block is valid (see below).
  8. Add to chain: every node appends the block, and Ali sees the funds.
  9. Confirmations: each later block built on top makes reversal less likely.
How a transaction becomes part of a blockchainTransaction: A user signs and submits it. Broadcast: Sent to nodes on the network. Validation: Nodes check rules and signatures. New block: Valid transactions are grouped. Consensus: The network agrees on the block. Chain: Block is linked and permanentTransactionA user signs and submits itBroadcastSent to nodes on the networkValidationNodes check rules andsignaturesNew blockValid transactions aregroupedConsensusThe network agrees on theblockChainBlock is linked andpermanent
Diagram: How a transaction becomes part of a blockchain.

Hashing and linking

A hash function turns any data into a fixed-length fingerprint. A block stores its own hash and the previous block's hash:

Block 1: hash = H(data1, 000...)
Block 2: hash = H(data2, hash of Block 1)
Block 3: hash = H(data3, hash of Block 2)

If someone edits data in Block 1, its hash changes, so Block 2's stored reference no longer matches, and so on. An attacker would have to redo the work for all later blocks faster than the honest network adds new ones.

Merkle trees

Transactions inside a block are combined into a tree of hashes whose single top value (the Merkle root) is stored in the block header. This lets light clients prove a transaction is in a block without downloading everything.

Consensus mechanisms

MechanismHow a block is chosenTrade-offs
Proof of Work (PoW)Miners compete to solve a hard puzzle; the winner adds the blockVery secure, but energy-intensive and slower
Proof of Stake (PoS)Validators lock up coins as a stake and are selected to propose and attest to blocksFar less energy; dishonest validators can lose their stake
Permissioned (BFT-style)Known validators voteFast, but trust is placed in the approved group

A simple proof-of-work illustration

import { createHash } from 'node:crypto';

function mine(data, difficulty = 4) {
  let nonce = 0;
  while (true) {
    const h = createHash('sha256').update(data + nonce).digest('hex');
    if (h.startsWith('0'.repeat(difficulty))) return { nonce, hash: h };
    nonce++;
  }
}

console.log(mine('Sara pays Ali 1'));

The miner changes the nonce until the hash begins with enough zeros. Finding it is slow; checking it is instant. That asymmetry is the core of proof of work.

Forks and finality

Sometimes two valid blocks appear at nearly the same time. Nodes keep the longest (or heaviest) valid chain, and the shorter branch is dropped. This is why exchanges wait for several confirmations before treating a payment as final.

Why attacks are hard

  • Forging a signature would require a private key.
  • Rewriting history means redoing the work (or controlling the stake) for all later blocks.
  • 51% attacks need control of most of the network's power. On large chains this is extremely expensive; small chains are more vulnerable.
  • Double spending is detected because every node checks the shared history.

What a node does

Full nodes store the chain, validate everything independently and relay data. Because each node verifies the rules itself, you do not need to trust any single node.

Beyond payments

Chains like Ethereum also run programs, called smart contracts, as part of block processing; read smart contracts explained.

Next steps

Start with the overview in what blockchain is.