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 /mine
mines the current blockGET /chain
returns the full chain in JSONGET /chain/valid
tells you whether the current chain is validPOST /chain/index
to get the block on a certain index. The format is:
{
"index": 1
}
POST /chain/range
to 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 /load
loads the previous used blockchainGET /transactions/current
show the transactions which are not yet placed in a blockPOST /transactions/new
to create a new transaction. The format is:
{
"sender": "your hash",
"recipient": "the other hash",
"amount": 123
}
POST /block/valid
validates 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/resolve
to resolve conflictsPOST /nodes/register
to add a list of new nodes using the following format:
{
"nodes": ["An ip adress or website"]
}