This project contains a blockchain with an API and support for multiple nodes. The blockchain code has validations mechanisms to verify blocks, transactions and the entire chain. Every block hash starts with four zeros. Transactions are validated using a Merkle Tree.
Install ruby and the bundler gem. Run bundle.
Enter ruby app.rb in your favorite terminal to start the server.
The application can be accessed via localhost:4567.
The server can do the following requests:
GET /minemines the current blockGET /chainreturns the full chain in JSONGET /chain/validtells you whether the current chain is validPOST /chain/indexto get the block on a certain index. The format is:
{
"index": 1
}POST /chain/rangeto get a range of blocks. When you omit the 'to' parameter you will get the chain to the end. The 'from' parameter is required. The format is:
{
"from": 1,
"to": 4
}GET /loadloads the previous used blockchainGET /transactions/currentshow the transactions which are not yet placed in a blockPOST /transactions/newto create a new transaction. The format is:
{
"sender": "your hash",
"recipient": "the other hash",
"amount": 123
}POST /block/validvalidates a block for you. The required format is:
{
"index": 0,
"timestamp": 0,
"transactions": [],
"previous_hash": "0",
"merkle_root": "0",
"proof": 0
}For multiple nodes you can use the following requests:
GET /nodes/resolveto resolve conflictsPOST /nodes/registerto add a list of new nodes using the following format:
{
"nodes": ["An ip adress or website"]
}