The API implemented for this project serves as a wrapper to the SmartContract, and facilitates the integration with Front-End applications. The API here mentioned was implemented in Node.js, as an integration of a Next.js project.
Below, see the description of the API endpoints.
POST: Register
POST /api/users/register HTTP/1.1
Host: URL:PORT
Content-Type: application/json
Content-Length: --
{
"firstName":"John",
"lastName":"Doe"
"username":"johndoe",
"password":"****"
}
POST: Authenticate
POST /api/users/authenticate HTTP/1.1
Host: URL:PORT
Content-Type: application/json
Content-Length: --
{
"username":"johndoe",
"password":"****"
}
All the following endpoints require previous authentication via JWT token.
POST: Balance
POST /api/users/balance HTTP/1.1
Host: URL:PORT
Content-Type: application/json
Content-Length: --
{
"userId":2
}
All the following endpoints can only be called by the user that has the wallet Public Address the same as the owner of the contract.
GET: GetUsers
GET /api/users HTTP/1.1
Host: URL:PORT
Content-Type: application/json
POST: Mint
POST /api/users/mint HTTP/1.1
Host: URL:PORT
Content-Type: application/json
Content-Length: --
{
"userId":2,
"amount":100
}
POST: Deduct
POST /api/users/deduct HTTP/1.1
Host: URL:PORT
Content-Type: application/json
Content-Length: --
{
"userId":2,
"amount":50
}
How to run
To run the API, the user must have installed Node.js and must download the project from the GitHub repo. After that, navigate to the frontend folder of the project. The following .env file must be created in the root of the frontend folder.
BLOCKCHAIN_NETWORK_URL=http://localhost:8545
BLOCKCHAIN_CHAIN_ID=31337
BLOCKCHAIN_PRIVATE_KEY="PRIVATE KEY OF THE HARDHAT ACCOUNT INDEX ZERO"
BLOCKCHAIN_CONTRACT_ADDRESS="ADDRESS OF THE CONTRACT DEPLOYED IN LOCALHOST"
BLOCKCHAIN_OWNER_ADDRESS="ADDRESS OF THE HARDHAT ACCOUNT INDEX ZERO"
BLOCKCHAIN_START_AMOUNT=100