A blockchain in 200 lines of code

Block structure

The hash of the previous block must be found in the block to preserve the chain integrity

Block hash

Generating a block

Storing the blocks

Validating the integrity of blocks

Choosing the longest chain

Communicating with other nodes

  • When a node generates a new block, it broadcasts it to the network
  • When a node connects to a new peer it querys for the latest block
  • When a node encounters a block that has an index larger than the current known block, it either adds the block the its current chain or querys for the full blockchain.
Some typical communication scenarios that follows when the nodes obey the described protocol

Controlling the node

  • List all blocks
  • Create a new block with a content given by the user
  • List or add peers
#get all blocks from the node
curl http://localhost:3001/blocks

Architecture

The main components of NaiveChain

Conlusions

--

--

--

I like programming and Careless Whisper. http://bit.ly/JMRmkU

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

W3A Demo completed | Phala Updates v.0.1.2 (4.6–4.12)

Blockchain solutions are setting a new foundation for microinsurance.

Blockchain in the Boardroom: Toward Enterprise Deployment

Trace Network Partners with Biconomy to bring frictionless and smooth gasless transactions to…

Phala Testnet Vendetta Is Live🚀

Hitting a new milestone: Contentos TestNet and New Website Launch

How the world’s first NFT podcast keeps on giving

Phala to Provide Scalable, Privacy-Preserving Cross-chain Transactions for DeFi dApps and NFTs on…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Lauri Hartikka

Lauri Hartikka

I like programming and Careless Whisper. http://bit.ly/JMRmkU

More from Medium

Emp.Money — The First Algo Stable Coin To Succeed?

WHAT IS THE LIGHTNING NETWORK?

SpaceGate Finance is your BEST solution

5 LEADING CRYPTO WALLETS YOU SHOULD TRY OUT IN 2022