fullstack-blockchain-app: cryptochain: The blockchain where your balance is a calculation

Inside `zubair-trabzada/fullstack-blockchain-app`, a clean-room Node and React implementation that rebuilds money, mining, and node sync from first principles.

8 min read • View on GitHub • More from zubair-trabzada

A ledger and a wallet sit side by side on a workbench, while transaction slips move between them in a chain. The wallet looks less like a container and more like a device that reconstructs its state from history, which is the central idea the article explains.
The repo’s core lesson is that a wallet is not a box of money. It is a calculation built from the chain.
Key Takeaways

Most blockchain tutorials start with the wrong object. They show you a balance and ask you to trust it. cryptochain does the opposite. It makes the wallet prove its balance by walking the chain, which is the right mental model for understanding why blockchains are auditable, brittle, and useful.

Money is not stored. It is inferred.

The sharpest idea in zubair-trabzada/fullstack-blockchain-app lives in the wallet. A balance is not read from a row in a database. It is reconstructed by scanning blockchain history, finding the last time the wallet spent funds, then adding every relevant output that arrived after that point.

calculateBalance({ chain, address }) {
  let hasConductedTransaction = false;
  let balance = INITIAL_BALANCE;

  for (let i = chain.length - 1; i > 0; i--) {
    for (const blockTransaction of chain[i].data) {
      if (blockTransaction.input.address === address) {
        hasConductedTransaction = true;
        balance = blockTransaction.outputMap[address];
      }

      if (blockTransaction.outputMap[address]) {
        balance += blockTransaction.outputMap[address];
      }
    }

    if (hasConductedTransaction) break;
  }

  return balance;
}

This is the key mental model. The wallet scans backward until the last outgoing transaction, then counts only what arrived after that boundary.

That is a clever compromise. The code does not re-sum every transaction from genesis on each render, but it still preserves the core truth that value comes from history. It is a UTXO-adjacent idea without the ceremony, which makes it perfect for teaching.

The goal is to provide a clear, hands-on example that bridges the gap between frontend and blockchain development.

Zubair Trabzada, Creator · Medium post

Proof of work that breathes

A close-up mining machine presses against a narrowing steel seam while a gauge tightens beside it. The image explains how difficulty adapts over time, so the chain keeps block production near its target rate instead of letting mining run too fast or too slow.
Mining here is not just brute force. The target changes as the chain learns how quickly blocks are arriving.

The mining loop is more interesting than the usual cartoon version. In Block.mineBlock, the code keeps hashing until the binary form of the hash begins with enough leading zeroes. Then adjustDifficulty nudges the target up or down so block times stay near the configured rate.

mineBlock({ lastBlock, data }) {
  let hash, timestamp;
  let nonce = 0;
  let difficulty = lastBlock.difficulty;

  do {
    nonce++;
    timestamp = Date.now();
    difficulty = Block.adjustDifficulty({ originalBlock: lastBlock, timestamp });
    hash = cryptoHash(timestamp, lastBlock.hash, data, nonce, difficulty);
  } while (
    hexToBinary(hash).substring(0, difficulty) !== '0'.repeat(difficulty)
  );

  return new this({
    timestamp,
    lastHash: lastBlock.hash,
    hash,
    data,
    difficulty,
    nonce
  });
}

That binary check matters. Hex gives you coarse jumps. Binary gives you the finer control you need when the chain has to respond to timing instead of pretending every block arrives on schedule.

A node is just a synchronized opinion

A single node at a desk receives matching sealed envelopes from several neighboring nodes and checks them against a rulebook before filing one away. The scene explains that network sync is not magical consensus, but repeated validation of incoming state.
The network layer is simple on purpose. Nodes publish state, other nodes validate it, and the chain only changes when the rules agree.

Once a block is mined, the node broadcasts it through pub/sub. Other nodes receive the update, validate the chain, and replace local state only if the new chain is longer and still valid. New peers can also bootstrap from a root node, which is a pragmatic shortcut, not a claim of perfect decentralization.

pubsub.subscribe(({ blockchain }) => {
  blockchain.replaceChain(receivedChain, true, () => {
    transactionPool.clearBlockchainTransactions(receivedChain);
  });
});

async function syncWithRootState() {
  const chain = await fetch(`${ROOT_NODE_ADDRESS}/api/blocks`).then(r => r.json());
  const transactionPool = await fetch(`${ROOT_NODE_ADDRESS}/api/transaction-pool`).then(r => r.json());
  // hydrate local node state from the root node
}
QuestioncryptochainFramework starters
What holds your money?A balance computed from chain history.A state value that is usually hidden behind app plumbing.
What is the hard part?Making validation explicit and readable.Hiding protocol details behind tooling and conventions.
How does mining behave?Difficulty adapts to block timing.Mining is often abstracted away or mocked.
Who gets the most value?Readers learning how a blockchain works.Teams that want to prototype faster with less friction.

That is why this repo teaches better than a heavier starter kit. Frameworks are great at removing friction. This project is great at removing illusions. When you can see the chain, the wallet, the miner, and the network as separate, testable ideas, the protocol stops feeling mystical.

Why this repo teaches better than a framework starter

The alternatives in the ecosystem are stronger on breadth. Scaffold-ETH gives you a larger surface area, create-eth-app gives you a quick scaffold, and Hardhat gives you the expected development loop. zubair-trabzada/fullstack-blockchain-app is narrower than all of them, but that narrowness is the point. It keeps the protocol visible.

The goal is to provide a clear, hands-on example that bridges the gap between frontend and blockchain development.

Zubair Trabzada, Creator · README.md

There is a cost. The project leans on a root node for bootstrap, it does not attempt full peer discovery, and it feels like what it is, a disciplined prototype. That is a feature in an explainer repo. You learn more from a small machine with the covers off than from a polished machine that refuses to show you its gears.