This project is developed in the context of the Udacity Blockchain Nanodegree
The goal of this project is to build a dApp (Decentralized application) using smart contracts and web3 technology. This project tackles these specific points:
- Multi-party consensus
- Oracles
- Receive, transfer and send funds
- Smart Contract upgradability
- Fail fast contracts
In this app a passenger can:
- Subscribe insurance to a flight
- If the flight is delayed due to the company the passenger will get 1.5x the amount of ether he put in the insurance
- The passenger can withdraw the ether from the smart contract
For airlines, the smart contract allows to:
- Submit a new airline to the smart contract
- Vote for a new airline to reach a 50% consensus
- Add a flight
We have a server that simulates the behavior of oracles that:
- Listen to a specific event that the smart contract will trigger when info about a flight is needed
- Generate the info about flights and send them to the smart contract
- Compile the smart contracts: from the root of the project make a
truffle compile
(you must have truffle installed globally) - Run the local chain doing
npm run chain
oryarn run chain
- Deploy the smart contract doing
truffle migrate
- Launch the server doing
cd src/server && npm i && npm start
- Launch the dapp doing (from the project root)
cd src/dapp && npm i && npm start
(IMPORTANT: be sure to launch the dapp only once the smart contract have been deployed, since the dapp use files that are exported when smart contracts are deployed) - Connect Metamask to a custom JSON RPC :
http://127.0.0.1:8545
(and be sure to re intialize Metamask each time your recompile et re migrate the smart contracts)
- Run the local chain doing
npm run chain
oryarn run chain
- From the project root make a
truffle test
Get insurance for a flight
The first block allows you to choose a flight, enter an amount of ETH and validate to get insurance for a flight. You should not be able to put more than 1 ETH by flight.
Check Insurance amount
The second block allows you to check the amount you put in insurance for a specific flight
Fetch flight status
Choose a flight and click on the button. It will trigger the event that the Oracles listened. Oracles will answer with the flight status. For testing purpose, the Oracles will give back a status that triggers the insurance. At the bottom of the screen you should see your balance being updated (you received 1.5x the amount you put in the assurance, however your funds are still on the smart contract, you must withdraw them to get them in your wallet).
Your balance
Here you have the amount of ETH you own and that the smart contract still holds. You can withdraw them whenever you want.