(Shown on cover: Gavin Wood & Vitalik Buterin)

In this assignment, you will put your Solidity skills to the test. Feel free to reference the numerous contracts we’ve been through in lectures.

As with all assignments, don’t hesitate to Google, but do not copy verbatim or directly from your peers. Your code must compile and run to receive any credit.

Submission guidelines: Submit a single Solidity source file: HW3.sol

GitHub Classroom invite for HW3: https://classroom.github.com/a/g7l-jKhm

Deadline: Oct 6, 2022 at 16:00


1) Contract Structure

  1. Set open-source license to UNLICENSED.
    1. Contract should be named HW3
  2. Enforce compiler version 0.8.0 or above.

2) Standalone Functions (1%)

  1. Write a function that:
    1. Is named doMath
    2. Takes in two int256 as parameters
    3. Multiply each number by 2
    4. Return the sum of the product
  2. Write a function that:
    1. Is named getMax
    2. Takes in an array of uint256
    3. Returns the largest number in the array
  3. Write a function that:
    1. Is named hashStringArray
    2. Takes in an array of string
    3. Return an array of bytes32 that represent the hashes of the input strings
      1. Hint 1: keccak256(abi.encode(str)) returns a bytes32 hash of string str
      2. Hint 2: you need to create a memory array of type bytes32 and of the same length as the input string array

3) Building a Contact Book (2%)

Overview

You will build a contact book where anyone can hold a list of addresses as their contacts. There is no need to give each contact a nickname, as this will make things a bit more complicated.

Interface Requirements

In computer science, an interface often refers to a set of functions that you intend to expose to the outside world for people to interact with. In Solidity, an interface refers to a set of external functions. Only external functions can be a part of an interface.

The great thing about interfaces is that as a user, you don’t need to know the inner workings of the program. You only need to concern yourself with correctly calling the exposed functions. Similarly, in this assignment, we don’t care how the details are implemented (e.g. what types of variables to use, how they are named, etc.) — that is completely up to you. However, when we call a function it is expected to behave in a certain way, which is described to you in comments above each function.