A 3-Hour Lab on Ethereum Contract Development
tldr; I prepared a 3-hour lab session on Ethereum smart contract development. You can view the lab content here: www.respectedsir.com/ethlab
Context
I am associated with the recently established Trust Lab at IIT Bombay. In December 2022, the lab organized a Winter School on Digital Trust in association with ACM India. I was tasked with delivering some lectures on cryptocurrencies and conducting a lab on smart contract development. This post is about the design and conduct of the lab. The lecture videos are available at the following links.
Lab Content
The lab slot was 3 hours long. Most of the winter school attendees were 3rd year CS undergraduates from all over India. No prior exposure to smart contract development was assumed of them.
When designing the lab content, I made the following choices:
- Ethereum: The lab exercises would involve only Ethereum.
- This was a no-brainer as Ethereum is the most popular platform for smart contracts. Several other independent blockchains have chosen the Ethereum Virtual Machine (EVM) as their execution engine.
- Deployment on Testnet: All contract deployments would be on an Ethereum tesnet (Goerli).
- Con: Deploying to an Ethereum testnet would require each student to get testnet ETH from a faucet. This is an additional step that can be avoided in local deployments.
- Pros: The workflow is closer to deployments to Ethereum mainnet.
- The deployed contracts and subsequent interactions can be viewed on the Goerli Etherscan blockchain explorer.
- NFTs minted on Goerli can be viewed on the testnet versions of NFT explorers like OpenSea.
- Two workflows: The lab would cover two different workflows based on Remix and Hardhat for smart contract development.
- Remix is a browser-based IDE for Ethereum smart contract development. As it requires no software installation, the workflow is simpler. It would enable students to get to contract deployment faster.
- Hardhat is a command-line tool for Ethereum smart contract development. It requires an installation of NodeJS to work. It can be paired with an editor like Visual Studio Code for contract development.
- Hardhat appears to be more popular than Remix for building contract deployment scripts. For example, the Ethereum tutorials on Alchemy's Web3 Tutorials site all use Hardhat.
- If the Hardhat setup were to fail (and it did for some students using Windows), the Remix workflow could be used as a fallback option.
- Four contracts: The students would deploy four contracts in the ab. Three using Hardhat and one using Remix.
- Two simple contracts, one each to illustrate the Remix and Hardhat workflows. Both involve storing and updating a variable in a smart contract.
- An ERC-20 Token Contract: ERC-20 tokens are a killer app on Ethereum. By deploying an ERC-20 contract, students would create a new token on Ethereum. The token is effectively a cryptocurrency with automatic support in wallets like Metamask.
- An ERC-721 NFT Contract: Non-fungible tokens attracted mainstream media attention in 2020-21. By deploying an NFT contract, students would learn about how they work.
- Use Alchemy Tutorials: All three of the contracts that were to be deployed using the Hardhat workflow were based on Alchemy's tutorials (with some minor modifications).
- Alchemy is a provider of blockchain infrastructure-as-a-service. Its website hosts several tutorials on smart contract development on Ethereum and other blockchains. These tutorials are free and of high quality.
- The catch is that the tutorial content involves using the Alchemy RPC endpoints and API keys. This would require each student to create a free tier account. The account signup does not require a credit card.
- The upside of having an Alchemy account was that each student could get 0.2 Goerli testnet ether from Alchemy's faucet at the beginning of the lab session. This much ether would be sufficient to deploy all four contracts.
- mdbook-based Lab Manual: I created a lab manual using mdbook. It is available at https://www.respectedsir.com/ethlab.
- An mdbook site works better than a pdf-based manual for navigation. Also, copy-and-paste of code snippets from pdf documents may not work well.
- The manual suggested a linear flow for the lab session starting from the prerequisites all the way to the NFT contract.
- The Alchemy tutorials for the different contracts are meant to be read independently and have some repetition. In the manual, I could remove these redundancies.
- Additional context and steps could be added at appropriate places. For example, I added the procedure to upload the NFT metadata to IPFS using Pinata and to view the deployed NFT on Opensea testnet.
Lab Execution
The students were sent a link to the lab manual and asked to work through it on their laptops. After successfully completing a testnet contract deployment, they were asked to enter the Etherscan link to the contract into a Google form.
This form enabled real-time feedback on the progress of the students. It also illustrates the advantage of deploying the contracts on a public testnet. The instructor can check the contract deployments without looking into each student's laptop.
Venue
The venue was the new Collaborative Classroom in the EE department of IIT Bombay. It has hexagonal tables each seating upto six students. The layout allowed the TAs and me to walk around debugging the issues faced by the students.
Alchemy Faucet Issue
One unexpected issue was that the Alchemy faucet failed to give some students Goerli ether even though they had created an Alchemy account. This was fixed by having these students access the faucet website using their mobile phone internet, and not through the IIT Bombay network.
Maybe Alchemy had implemented IP address-based rate limiting. All the student requests could have appeared to be coming from the small set of IIT Bombay public IP addresses.
Acknowledgment
I want to thank the TAs — Varun Thakore, Mayank Taneja, Kaartik Bhushan, Darshit Gandhi — who helped conduct this lab session. The students enjoyed it (see smiles here).
- Previous: My PPoT Participation Experience