First Blockchain With Java
First Blockchain With Java
with Java.
We will be using Java but you should be able to follow along in
any OOP language. I’ll be using Eclipse but you can use any new
fancy text editor ( though you’ll miss out on a lot of good bloat ).
Don’t worry if your eclipse looks different to mine. I’ll be using a dark theme in eclipse
because ^
Optionally, you can grab GSON library by google (who are they
???). This will allow us to turn an object into Json \o/. It’s a
super useful library that we will also be using further down the
line for peer2peer stuff, but feel free to use an alternate method.
In Eclipse create a (file > new > ) Java project. I’ll call my Project
“noobchain” and create a new Class by the same name
(NoobChain).
Don’t be copying my project name now ( ͠° ͟ ͜ʖ ͡°)
What does this mean ? …Changing any data in this list, will
change the signature and break the chain.
As you can see our basic Block contains a String hash that will
hold our digital signature. The variable previousHash to hold the
previous block’s hash andString data to hold our block data.
The first block is called the genesis block, and because there is
no previous block we will just enter “0” as the previous hash.
Each block now has its own digital signature based on its
information and the signature of the previous block.