Homework 1: Programming in Solidity [100 points]

In this assignment you will learn to program smart contracts in Solidity.

Learning Goals:

In this assignment you will learn..

  1. The basic syntax and semantics of the Solidity language
  2. Creating an application which accepts, holds, and transfers Ethereum
  3. How fork an Ethereum network
  4. Navigating Hardhat framework

Part 1 Instructions:

In this assignment you will write a smart contract, in Solidity, for an NFT auction. The auction will be for the course NFT you minted in HW0.

  1. Install Hardhat and create a project:

    1. Overview of Hardhat and instructions here: https://hardhat.org/hardhat-runner/docs/getting-started#overview

    2. Once you’re done, you should have a placeholder Lock project with the following directory structure:

      Screen Shot 2022-08-31 at 11.26.24 PM.png

  2. Replace the Lock placeholder files with our HW1 files:

    Auction.sol

    Auction.txt

    Auction.txt is the test file. Place it in the test directory then run mv Auction.txt Auction.js (Notion doesn’t allow us to upload js files)

  3. Write your NFT auction!

    The auction’s sequence of events might be as follows:

    1. Owner opens the auction
    2. Bidder1 makes a bid
    3. Bidder2 makes a bid higher than **Bidder1’**s ****bid
    4. Bidder3 makes a bid higher than Bidder2’s bid
    5. Bidder1 realizes they’ve been out bid and ups their bid
    6. Auction continues like this with bidders competing for the highest bid…
    7. Owner closes the auction
    8. The winner (highest bidder) is transferred the NFT
    9. The losers are refunded their bids

There will be two roles in this auction:

  1. Owner - The owner is the account that deployed the smart contract. The owner, and only the owner, should be able to do the following:
    1. Start the auction
    2. End the auction
    3. Payout the winner
  2. Bidder - The bidders are competing to win the NFT. They should be able to do the following:
    1. Make a bid
    2. Up a bid if someone outbids them
    3. Get their funds returned if they lost the auction

When your auction contract is deployed, it is neither open nor closed. It is in an idle state. When the auction begins, it is active. When it ends, it is closed.

Open the template code and follow the instructions to implement each function.

  1. Run npx hardhat test to test your Auction.

    1. Every test should pass except one:
    Auction
         Payout Winner
         The winner's balance should go to 0:
         Error: Transaction reverted: function call to a non-contract account
    

This error is coming from a test of our payoutWinner function. This function, which we’ve implemented, transfers the HW0 NFT to the winner.

function payoutWinner() public /* MODIFIER(S) */ {
        fundsPerBidder[highestBidder] = 0;
        nft.enterAddressIntoBook("auction");
        nft.mintNFT();
        nft.transferFrom(address(this), highestBidder, 2);
}