90 minutes ⇒ Level: High
Smart Contract Implementation (45 minutes)
- Review the project scenario and explain to the students that the primary goal of this session is to implement a smart contract.
- Demonstrate the steps for setting up a Hardhat project (including installation), ensuring to highlight that this project should be organized within a distinct directory, separate from the one established in the previous module for facilitating communication between the Raspberry Pi and the 3D printer.
- Instruct students to create a new directory named
contracts
inside the Hardhat project and to create a.sol
file within this directory. It is recommended to name the file after the contract it contains, as this is a
common practice. - Instruct groups of students to implement the smart contract according to the design outlined in the previous session.
- Assist students with the implementation of value and reference types. Assist with the implementation of smart contract functions, modifiers, and the visibility settings of these functions.
- Show students the command for compiling contracts and provide guidelines for debugging errors that may arise during compilation.
Smart Contract Testing (30 minutes)
- Emphasize the necessity of conducting thorough testing for smart contracts, particularly before deploying them on actual blockchain networks, to account for the irreversibility of transactions.
- Instruct groups of students to create a new directory named
test
and to create a new file within it (e.g. Test.js). - Explain that ethers.js will be utilized for interacting with the smart contract, and Mocha will serve as the test runner. Provide examples of code that uses these mentioned tools for testing smart contracts.
- Encourage students to carry out deployment tests for their smart contracts and to conduct as many functionality tests as they find necessary. Offer assistance with the implementation and provide guidelines for debugging any errors that may arise.
Smart Contract Deployment (15 minutes)
- Inform students that once a smart contract has been implemented and tested, it is time to deploy it on the network.
- Emphasize that in our scenario, we will not utilize an existing live blockchain network such as Ethereum; instead, we will use a local network. Direct students to initiate the Hardhat Network by providing the
appropriate command. - To deploy a smart contract on the established network, a deployment script is required. Guide the students to create a file (for example,
deploy.js
) inside the scripts folder, which will be utilized for deployment. Provide students with an example of the code necessary to execute the deployment of a smart contract. Support students in implementing the deployment script for their own smart contracts. - Introduce the command necessary to deploy a smart contract on a local network and motivate students to deploy their own smart contracts on their local networks.