Final Year Project (FYP 2023-2024)
Riccardo Sottini
Aston University
The following are the steps to configure the system components.
Install Hardhat, a package helping developers to automate the deployment of a smart contract on the blockchain network.
npm init --y
npm install --save-dev hardhat
npm install --save-dev @nomiclabs/hardhat-ethers ethers @nomiclabs/hardhat-waffle ethereum-waffle chai
To deploy a contract, Hardhat needs to have the url of the endpoint, along with the private key of the used account (which can be retrieved through MetaMask).
Once the variables are retrieved, they can be stored by hardhat by typing them in the terminal.
npx hardhat vars set ENDPOINT_URL
npx hardhat vars set PRIVATE_KEY
Hardhat produces the bytecode of the smart contract, along with its ABI and stores them locally.
npx hardhat compile
Once the configuration and compilation of the contract is completed, it can be deployed remotely.
As the contract is deployed, the terminal will show to which address it has been published.
npx hardhat run scripts/deploy.js --network amoy
Install the version 3.7 of Python. The following command is used to install the useful libraries (Web3, RPi.GPIO, asyncio)
pip install web3 RPi.GPIO asyncio
Retrieve the deployed contract address and ABI, and retrieve the HTTPS blockchain gateway endpoint.
Set the environment variables in the configuration file:
provider_endpoint = HTTPS endpoint api url
contract_address = Deployed contract address
contract_abi = Deployed contract ABI definition
Use the following command to install the libraries used by the project:
npm install
Retrieve the deployed contract address and ABI, and retrieve the WSS blockchain gateway endpoint.
Set the environment variables in the configuration file:
provider_endpoint = WSS endpoint api url
contract_address = Deployed contract address
contract_abi = Deployed contract ABI definition
To run the entire system, there is the need to:
- run the frontend on the server
- run the door script on the Raspberry Pi microcontroller
The frontend can either be run in the dev environment (during the development phase), or compile it and run it in the production environment.
The development environment can be run with this command:
npm run dev
The production environment can be run with these commands:
npm run build
npm start
The script needs to be run on the Raspberry Pi microcontroller with internet connection. The following command is used to run the script:
python script.py
Various scripts were developed for evaluating the time performance and estimated gas fees for the contract methods. The scripts need to be configured by setting up the following configuration variables in includes/config.json:
- user_address
- private_key
- provider_endpoint_send
- provider_endpoint_fetch
- contract_address
- contract_abi
The evaluation scripts can be run with the following commands:
npx hardhat run scripts/evaluate_access.js --network amoy
npx hardhat run scripts/evaluate_methods.js --network amoy
npx hardhat run scripts/estimate_gas.js --network amoy