This exam layout needs a larger screen. Please open it on a desktop computer.
Theory
Answer the following questions to the best of your ability. Each question has exactly one correct answer. There are no negative marks for incorrect answers.
Coding - Viem: Contract Explorer
In the repository you downloaded, there is a directory called /scripts. Inside, there is a file called contract-explorer.ts, which is used to analyze an ERC-20 contract (for fungible tokens) on the Next Testnet network, and to get the balance of a specific Ethereum address within that contract. Your job is to complete the script so that it prints the following information for the contract:
- The name
- The symbol
- The decimals (for example, for PAXG it's 18 decimals, like Wei and Ether)
- The balance (in that contract), for a specific address
You can test the script by running the following command:
npx tsx scripts/contract-explorer.ts
To understand what options are available for ERC-20 tokens, you should start by clicking the "Read contract" tab here: view contract.
For testing, you can use the following information:
| Type | Address |
|---|---|
| Contract address | 0x5FbDB2315678afecb367f032d93F642f64180aa3 |
| Account address | 0xa24d14702cef666131dd8EFC0670318CDCA4Baf3 |
Hint: you only need to use the readErc20Contract function, which is already provided for you in the starter template.
Coding - Hardhat: Gradebook
In the repository you downloaded, there is a directory called /contracts (for storing smart contracts), and a directory called /test (for test files). In the first directory, there is a file called Gradebook.sol (where you need to write a smart contract in Solidity); while in the second directory, there is a file called Gradebook.ts (where you need to write tests for the contract).
The contract is meant to be used by a teacher as a public Gradebook, for storing points and calculating grades for students. It should support 3 functions:
- addStudent(addr, name) - for adding a new student (with their Ethereum address and name).
- submitScore(addr, points) - for storing the number of points earned by the student (a number between 0 and 100). Points can only be set once for a student and can't be overridden. An event should be fired with the address and the number of points.
- getGrade(addr) - a view function that calculates a grade based on the points and returns a number between 5 and 10.
The contract should validate the inputs, and return errors if something is not correct. For calculating a grade based on the number of points, you can use the standard scoring system used at Brainster Next (91-100 is a 10, 81-90 is a 9, ..., and anything below 51 is a 5).
You can build the contracts by running the following command:
npx hardhat build
After you code the contract, you can start adding tests in the test/Gradebook.ts file (it already has a list of tests you need to add). To run them, you can use the following command:
npx hardhat test
Hint: you have an example contract and tests (see Documentation links on the top) to help you get started.