In this assignment you will learn to program smart contracts in Solidity.
In this assignment you will learn..
- The basic syntax and semantics of the Solidity language
- Creating an application which accepts, holds, and transfers Ethereum
- How to fork an Ethereum network
- Navigating Hardhat framework
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 the previous homework.
-
Install Hardhat and create a project:
- Overview of Hardhat and instructions here: https://hardhat.org/hardhat-runner/docs/getting-started#overview
- Once you’re done, you should have a placeholder Lock project with the following directory structure:
-
Replace the
Lock
placeholder files with our HW1 files:Auction.sol
(under/contracts
) andAuction.js
(under/tests
) (These are provided in the repo folders above) -
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 bidsThere 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:
a. Start the auction
b. End the auction
c. Payout the winner- Bidder - The bidders are competing to win the NFT. They should be able to do the following:
a. Make a bid
b. Up a bid if someone outbids them
c. 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.-
When you've completed your code, 1. Run
npx hardhat test
to test your Auction. 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 course NFT to the winner.function payoutWinner() public /* MODIFIER(S) */ { fundsPerBidder[highestBidder] = 0; nft.enterAddressIntoBook("auction"); nft.mintNFT(); nft.transferFrom(address(this), highestBidder, 2); }
The hardhat test is failing due to the calls on the
nft
object.This error means that the NFT contract address we passed in the constructor doesn’t exist… Let’s see the address we sent to the constructor in line 17 of our hardhat test:
const auction = await Auction.deploy("0x978A328Cc24C0b50a0D9F97787938E67CF09F9A9", 1);
If you check that address in the Etherscan Goerli test network, you’ll see it is our course NFT contract. So, why does Hardhat complain that the contract doesn’t exist?
Hardhat has no knowledge of the Ethereum networks. The tests start with a blank slate blockchain with no contracts and only a small set of initial accounts.
- Bidder - The bidders are competing to win the NFT. They should be able to do the following:
In this part you will learn how to fork the test net so Hardhat has knowledge of our HW0 NFT contract.
In this part, you will need to interact with our existing course contract. To test this interaction, you will need to fork the Ethereum Georli test net.
As a warm-up for these learning goals, complete the following exercise: Fork the F*ing Ethereum Blockchain! Transfer tokens from Vitalik’s Account ;)
In the article, there is a line that says “there is literally 0 sense for you to fork a testnet.” Ignore that :) For this assignment, it does make sense to fork the testnet.
Once you’ve completed the warmup you should have the knowledge needed to fix the last failing test. Modify your hardhat config to fork the Georli testnet from block number 8335158
.
Submit your Auction.sol
and hardhat.config.js
on gradescope.