Skip to content

A bitcoin Proof Of Concept made with AdonisJS framework. It implements the bitcoin structure, simplified and centralized, to be simpler.

License

Notifications You must be signed in to change notification settings

AdrienMorin/Blockchain-POC

Repository files navigation

Blockchain-POC

A Bitcoin Proof Of Concept made with AdonisJS framework. It implements the bitcoin structure, simplified and centralized, to be simpler.

Video presentation of the project : https://youtu.be/19DjOkj8JXI

Features

  • Login / Logout to a wallet
  • Get the wallet balance
  • Get the wallet public and private keys (using your login)
  • Get the blockchain (all the blocks with there transactions)
  • Create a transaction
  • Mine a block (include the created transactions into a block and add it to the blockchain : the minor (who call the mine route) will earn 4 bitcoins for transaction fee, which is generated and not paid by any sender)
  • Verify the blockchain (check if the blockchain is valid)

Project structure

This API is structured in the following way:

  • start/routes: Contains the routes of the API
  • app/Controllers/Http: Contains the controllers of the API called by the routes
  • app/Services: Contains the services of the API called by the Controllers.
  • app/Models: Contains the models of the API : User (the wallet), Block, BlockHeader, Transaction, Coin
  • database/migrations: Contains the migrations of the API to create the structure of the database
  • database/seeds: Contains the seeds of the API to put the first data in the database : Genesis block and first block
  • config: Contains the configuration files of the API : config of the database connection for example

Specificities

The blockchain is stored in a sqlite DB, in the tmp/db.sqlite3 folder.

In this version of the API, there is no possibility to create a new wallet. The only wallets are those which are created by the seeders. Those are the users credentials that you can use to login to the API :

[{
"firstname": "Adrien",
"lastname": "Morin",
"email": "[email protected]",
"password": "amorin123"
},
{
"firstname": "Jean",
"lastname": "Dupont",
"email": "[email protected]",
"password": "jdupont123"
},
{
"firstname": "Lucie",
"lastname": "Deschamps",
"email": "[email protected]",
"password": "ldeschamps123"
},
{
"firstname": "Baptiste",
"lastname": "Durand",
"email": "[email protected]",
"password": "bdurand123"
}]

You can use those credentials to login to the API and test the different endpoints. If you don't login you will not have access token and then not be able to access the routes When you login, you will receive a Bearer token that you will have to put in the Authorization header of your requests to the API.

There is an initialisation of the blockchain with a genesis block and a first block with some transactions in the seeders.

The users have some coins in their wallets to be able to make transactions :

  • Adrien Morin : 9 coins
  • Jean Dupont : 0 coins
  • Lucie Deschamps : 10 coins
  • Baptiste Durand : 35 coins

API requests examples

Login

POST http://127.0.0.1:3333/api/auth/login

{
    "email": "[email protected]",
    "password": "amorin123"
}

Logout

POST http://127.0.0.1:3333/api/auth/logout

GetIsLoggedIn

GET http://127.0.0.1:3333/api/ Authorization : Bearer

GetWallet

GET http://127.0.0.1:3333/api/wallet/getWallet Authorization : Bearer

GetWalletBalance

GET http://127.0.0.1:3333/api/wallet/getWalletBalance Authorization : Bearer

GetBlockchain

GET http://127.0.0.1:3333/api/blockchain/ Authorization : Bearer

CreateTransaction

Creates a transaction from the wallet of the connected account (related to the bearer token passed in the request) to another wallet POST http://127.0.0.1:3333/api/transactions/ Authorization : Bearer

{
  "receiverKey": "-----BEGIN PUBLIC KEY-----.....-----END PUBLIC KEY-----\n",
  "amount": 3
}

VerifyTransactionSignature

POST http://127.0.0.1:3333/api/transactions/verify Authorization : Bearer

{
  "transactionId": 6
}

MineBlock

Mine a block to add the created transactions into the blockchain. The minor is the connected account (related to the bearer token passed in the request). GET http://127.0.0.1:3333/api/blocks/mine Authorization : Bearer

VerifyBlockchain

GET http://127.0.0.1:3333/api/verify Authorization : Bearer

Setup and run the project

Using Docker

  1. Clone the project
  2. Run docker compose up

Running the project locally

  1. Clone the project
  2. Create a .env file at the root of the project with the following content :
PORT=3333
HOST=0.0.0.0
NODE_ENV=development
APP_KEY=5ZiLQYPgJKzNJIhy2OgjtZ_4Puj7gwgW
DRIVE_DISK=local

DB_CONNECTION=sqlite
  1. Install the dependencies with pnpm install
  2. Run the migrations with node ace migration:run
  3. Run the seeders with node ace db:seed
  4. Start the server with node ace serve --watch or pmpn run dev

About

A bitcoin Proof Of Concept made with AdonisJS framework. It implements the bitcoin structure, simplified and centralized, to be simpler.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published