Ethereum Dapp that allows users to register for Flight Insurance in case something happens to a flight.
Ethereum Dapp that allows users to register for Flight Insurance in case something happens to a flight. Part of the Udacity Blockchain Nanodegree.
This project uses: - ReactJS - Tailwind CSS - CSS - JS - NodeJS - EthersJS - Truffle - Ganache
React-JS - Easy to set up single page application with multiple pages.
Tailwind CSS - Easier to style components as compared to SCSS and CSS. Also more predictable and makes a site more responsive.
Ethersjs - Had lots of trouble using web3js and @truffle/contracts as I was getting lots of errors when using create-react-app. Resorted to using Ethers-js.
Ganache - A tool for creating a local blockchain for fast Ethereum development.
- Truffle version
v5.5.16
- Solidity version
0.8.14
- Node
v18
- Ganache
v7.2.0
The whole project runs on the latest nodejs version. Anything above v16
should work. To do this, ensure you have node version manager installed. Once installed you can then run.
nvm install node
nvm use node
To compile the smart contract, within the truffle development environment, run:
truffle compile
To run a local ethereum node, where you will deploy your contracts to, run ganache as shown below. This will create 50 accounts, some which will be used for the airline account, passenger account, owner account and oracles.
Warning Do not use the seed below in a public network.
ganache -a 50 -m "friend collect coconut snow pretty car anchor cross purchase exact biology about"
To migrate the contract to the ethereum chain, running on the node, run:
truffle migrate --reset
To run the test cases within the truffle development environment, run:
truffle test
The npm packages need to be installed in the client directory by running
cd client
and then
npm install
The client depend on a couple of files to work properly. One of them is the contract abi that should be located in the client/src/build
directory. To generate the contract abi in the correct location, run:
truffle compile --contracts_build_directory=./client/src/build
The second file is the configuration file that contains the node url, the url ganache runs in, the address of the data contract and the address of the app contract. This file is located in the client/src/data/config.local.json
and is generated by running:
truffle migrate --reset
Ganache needs to be running. Once this has been done, to run the backend of the project, you can run.
Once the installation process has been done, to run the frontend of the project, you can run.
npm start
The npm packages need to be installed in the api directory by running
cd client
and then
npm install
The backend api depend on a couple of files to work properly. One of them is the contract abi that should be located in the api/src/build
directory. To generate the contract abi in the correct location, run:
truffle compile --contracts_build_directory=./api/src/build
The second file is the configuration file that contains the node url, the url ganache runs in, the address of the data contract and the address of the app contract. This file is located in the api/src/data/config.local.json
and is generated by running:
truffle migrate --reset
Ganache needs to be running. Once this has been done, to run the backend of the project, you can run.
npm run start
To start the nodejs server in developer mode, you can run
npm run start-dev
Ensure Ganache is running
ganache -a 50 -m "friend collect coconut snow pretty car anchor cross purchase exact biology about"
To migrate the contract to the ethereum chain, running on the node, run:
truffle migrate --reset
To run the test cases within the truffle development environment, run:
truffle test
To run the test cases within the truffle development environment, run:
truffle test
UI testing is a bit complicated, to show the steps, a video can be found here. Make sure the seed is uploaded to Metamask to use the accounts.
Common issues:
Error when running test
1) Contract: FlightSurety App
For the (oracles)
should be able to register oracles:
Transaction: 0xaeb154bf26bfcee5f94d145ef87e41bb83e065cd3c46ecba5687973f2539139a exited with an error (status 0). Reason given: Panic: Arithmetic overflow.
Please check that the transaction:
- satisfies all conditions set by Solidity `require` statements.
- does not trigger a Solidity `revert` statement.
StatusError: Transaction: 0xaeb154bf26bfcee5f94d145ef87e41bb83e065cd3c46ecba5687973f2539139a exited with an error (status 0). Reason given: Panic: Arithmetic overflow.
at Context.<anonymous> (test/flight_surety_app.js:331:38)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
2) Contract: FlightSurety App
For the (oracles)
should be able to request flight status:
Error: Returned error: VM Exception while processing transaction: revert Not registered as an oracle
at Context.<anonymous> (test/flight_surety_app.js:357:12)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
Solution: Try running the test a couple of times. Sometimes this happens because the response has less than 3 indexes. If you try and run a couple of times, it should work.
I would/ We'd love to have your help in making FlightSurety better. The project is still very incomplete, but if there's an issue you'd like to see addressed sooner rather than later, let me(/us) know.
Before you contribute though read the contributing guide here: Contributing.md
For any concerns, please open an issue, or just, fork the project and send a pull request.
- see LICENSE file
- Version 1.0 DATE 15/06/2022
If you have found any bugs, or have any feedback or questions and or want to post a feature request please use the Issuetracker to report them.