Blockchain explained in Java

Quoting from Wiki

A blockchain, originally block chain, is a growing list of records, called blocks, which are linked using cryptography. Each block contains a cryptographic hash of the previous block, a timestamp, and transaction data (generally represented as a merkle tree root hash).


How about a functional code written in Java to understand Blockchain actual working.

We will create a Crypto Wallet
We will send amount from a wallet to another.

What are the basic Objects i can think of in the Crypto transactions ?

A Block which holds the valid transactions that are hashed and encoded.
A Wallet holding with the address and basic properties.
A Transaction which will happen when one send or receive.

Transaction input and output.

Classes created as below:

  • Block.java
  • BlockChainTransaction.java
  • BlockChainTransactionInput.java
  • BlockChainTransactionOutput.java
  • BlockChainWallet.java
  • PoloChain.java
  • UtilMain.java

Create Block Defination named Block.java

Create a helper class to process the transactions.

Class named BlockChainTransactionInput.

Class named BlockChainTransactionOutput .

Class named UtilMain providing helper functions.

Main Class named PoloChain which shows the lifecycle from creating the blockchain transaction to the final confirmation of the block.

Run the mail Class PoloChain.java to see how the wallets are created , genesis block creation , actual transfer from/to wallet resulting in the new block creation.

Download ?

Make a Fork Request here for any code repository within iseebug. http://www.iseebug.com/bitRequest

Leave a Reply

Your email address will not be published. Required fields are marked *

Blue Captcha Image
Refresh

*