How to program a blockchain

in #bitcoin6 years ago (edited)

Hello.
In this Tutorial I am going to show you how to program a simple blockchain in Java with my GitHub project Simple Blockchain API (SBA).

To use this project you have to implement this project in your Java project. Just open your IDE (I use eclipse) and import the ml.uniwide folder in your src package. Then you can use the Blockchain() class with:
Blockchain block = new ml.uniwide.Blockchain();
After importing your class you have to create your first Block in your Blockchain: the genesis Block. To do this you can use the method .setGenesisHash():

Object[] genesisHash = {"your genesis data"};
block.setGenesisHash(Arrays.hashCode(genesisHash));

To add a new Block to your Blockchain, you can use the .addBlock() method:

Object[] hash1 = {5100, "Hello World!"};
block.addBlock(hash1);

You can print out the hash of the previous Block with:
System.out.println(block.getPreviousHash());

To print out the complete blockchain list, you can use:
System.out.println(block.getList());

Thank your for using my SBA. Please support me on Steemit and GitHub.
BowStar