-
Compiled and deployed the contract before running the API. You can follow the instructions in the Contract documentation.
-
Install Node.js packages, nodemon and mocha
$ npm install $ npm install -g nodemon $ npm install -g mocha
-
Create a
.env
file Create a.env
file in the root directory of the project and add the following content:$ cp .env.example .env
Fill in the values for the following variables in the
.env
file:IP=<LOCAL_IP> PORT=<PORT_NUMBER> CHAIN_RPC=http://<IP>:8545 ADMIN_KEY=<KEY_TO_CREATE_PRIVATE_KEY> CONTRACT_ABI_PATH=../contract/build/ElectionContract.abi # don't need to change if you follow the default contract build path CONTRACT_ADDRESS_PATH=../contract/build/ElectionContract.address # don't need to change if you follow the default contract build path
ADMIN_KEY
should be the same with in the contract.env
file
$ npm run server
$ npm run start
$ npm run test
-
Edit the
docker-compose.yml
file for port mapping. -
Copy needed files to the
api/docker
directory
$ cp ../.env .
$ cp ../../contract/build/ElectionContract.address .
$ cp ../../contract/build/ElectionContract.abi .
- Now you need to change the
api/docker/.env
file with the correct values forCONTRACT_ABI_PATH
andCONTRACT_ADDRESS_PATH
CONTRACT_ABI_PATH=/app/docker/ElectionContract.abi
CONTRACT_ADDRESS_PATH=/app/docker/ElectionContract.address
- Run the Docker Compose file
$ docker-compose up -d