Skip to content

aagargoura/boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Private Blockchain Application

This project allows to demonstrate the fundamentals concepts of a Blockchain platform. Concepts like: - Block - Blockchain - Wallet - Blockchain Identity - Proof of Existance

  1. The application will create a Genesis Block when we run the application.
  2. The user will request the application to send a message to be signed using a Wallet and in this way verify the ownership over the wallet address. The message format will be: <WALLET_ADRESS>:${new Date().getTime().toString().slice(0,-3)}:starRegistry;
  3. Once the user have the message the user can use a Wallet to sign the message.
  4. The user will try to submit the Star object for that it will submit: wallet address, message, signature and the star object with the star information. The Start information will be formed in this format:
        "star": {
            "dec": "68° 52' 56.9",
            "ra": "16h 29m 1.0s",
            "story": "Testing the story 4"
    	}
  5. The application will verify if the time elapsed from the request ownership (the time is contained in the message) and the time when you submit the star is less than 5 minutes.
  6. If everything is okay the star information will be stored in the block and added to the chain
  7. The application will allow us to retrieve the Star objects belong to an owner (wallet address).

Used technologies?

  • This application will be created using Node.js and Javascript programming language. The architecture will use ES6 classes because it will help us to organize the code and facilitate the maintnance of the code.
  • The company suggest to use Visual Studio Code as an IDE to write your code because it will help you debug the code easily but you can choose the code editor you feel confortable with.
  • Some of the libraries or npm modules you will use are:
    • "bitcoinjs-lib": "^4.0.3",
    • "bitcoinjs-message": "^2.0.0",
    • "body-parser": "^1.18.3",
    • "crypto-js": "^3.1.9-1",
    • "express": "^4.16.4",
    • "hex2ascii": "0.0.3",
    • "morgan": "^1.9.1"

Libraries purpose:

  1. bitcoinjs-lib and bitcoinjs-message. Those libraries will help us to verify the wallet address ownership, we are going to use it to verify the signature.
  2. express The REST Api created for the purpose of this project it is being created using Express.js framework.
  3. body-parser this library will be used as middleware module for Express and will help us to read the json data submitted in a POST request.
  4. crypto-js This module contain some of the most important cryotographic methods and will help us to create the block hash.
  5. hex2ascii This library will help us to decode the data saved in the body of a Block.

Understanding the boilerplate code

The Boilerplate code is a simple architecture for a Blockchain application, it includes a REST APIs application to expose the your Blockchain application methods to your client applications or users.

  1. app.js file. It contains the configuration and initialization of the REST Api, the team who provide this boilerplate code suggest do not change this code because it is already tested and works as expected.
  2. BlockchainController.js file. It contains the routes of the REST Api. Those are the methods that expose the urls you will need to call when make a request to the application.
  3. src folder. In here we are going to have the main two classes we needed to create our Blockchain application, we are going to create a block.js file and a blockchain.js file that will contain the Block and BlockChain classes.

Starting with the boilerplate code:

First thing first, we are going to download or clone our boilerplate code.

Then we need to install all the libraries and module dependencies, to do that: open a terminal and run the command npm install

( Remember to be able to work on this project you will need to have installed in your computer Node.js and npm )

At this point we are ready to run our project for first time, use the command: node app.js

How to test the application functionalities?

We ca use POSTMAN, this tool will help to make the requests to the API.

  1. Run the application using the command node app.js You should see in your terminal a message indicating that the server is listening in port 8000:

Server Listening for port: 8000

  1. To make sure your application is working fine and it creates the Genesis Block you can use POSTMAN to request the Genesis block: Request: http://localhost:8000/block/0
  2. Make your first request of ownership sending your wallet address: Request: http://localhost:8000/requestValidation
  3. Sign the message with your Wallet: Use the Wallet to sign a message
  4. Submit your Star Request: http://localhost:8000/submitstar
  5. Retrieve Stars owned by me Request: http://localhost:8000/blocks/<WALLET_ADDRESS>

About

Private Blockchain Application with REST API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages