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
- 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)
This API is structured in the following way:
start/routes: Contains the routes of the APIapp/Controllers/Http: Contains the controllers of the API called by the routesapp/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, Coindatabase/migrations: Contains the migrations of the API to create the structure of the databasedatabase/seeds: Contains the seeds of the API to put the first data in the database : Genesis block and first blockconfig: Contains the configuration files of the API : config of the database connection for example
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
POST http://127.0.0.1:3333/api/auth/login
{
"email": "[email protected]",
"password": "amorin123"
}POST http://127.0.0.1:3333/api/auth/logout
GET http://127.0.0.1:3333/api/
Authorization : Bearer
GET http://127.0.0.1:3333/api/wallet/getWallet
Authorization : Bearer
GET http://127.0.0.1:3333/api/wallet/getWalletBalance
Authorization : Bearer
GET http://127.0.0.1:3333/api/blockchain/
Authorization : Bearer
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
}POST http://127.0.0.1:3333/api/transactions/verify
Authorization : Bearer
{
"transactionId": 6
}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
GET http://127.0.0.1:3333/api/verify
Authorization : Bearer
- Clone the project
- Run
docker compose up
- Clone the project
- Create a
.envfile 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
- Install the dependencies with
pnpm install - Run the migrations with
node ace migration:run - Run the seeders with
node ace db:seed - Start the server with
node ace serve --watchorpmpn run dev