Course 2 Project: Design and Development of Smart Contract

Sigit H. Yudanto
4 min readMay 24, 2022

Title: Auction for Fundraising for a Social Cause

Learning objectives:

  • To design, develop and test a smart contract for a problem using Solidity language and Remix IDE. (Module 1, and Module 2)
  • To apply incremental development method and best practices discussed in the course. (Module 3 and Module 4)

Problem Statement:

Consider the problem of Chinese auction or penny social. We will refer to it as simple “Auction.” It is a conventional approach used for fundraising for a cause. The organizers collect items to be auctioned off for raising funds. Before the auction, the items for auctions are received and arranged each with a bowl to place the bid. A chairperson is a special person among the organizers. She/he heads the effort and is the only person who can determine the winner by random drawing at the end of the auction. A set of bidders buy sheets of tickets with their money. The bidder’s sheet has a stub that identifies the bidder’s number, and tokens bought.

The bidders examine the items to bid, place the one or more tickets in the bowl in front of the items they desire to bid for until all the tickets are used. After the auction period ends the chairperson, collects the bowls, randomly selects a ticket from each item’s bowl to determine the winning bidder for that item. The item is transferred to the winning bidder. Total money collected is the fund raised by the penny social auction.

Assumptions:

The description given above is for a general penny social auction. For the sake of our project implementation we will introduce some simplifying assumptions. Here they are:

  1. Fixed number of bidders, initialized to 4. All 4 need to self-register. Funds transfer from bidder is automatically done and is not in the scope of this application.
  2. 2. Fixed number of items to be auctioned off, initialized to 3.
  3. 3. Items auctioned are indexed from 0..N-1 where N is the number of items for auction. N is 2.
  4. 4. Each bidder buys just 1 sheet of tickets or tokens; each sheet has only 5 tokens.
  5. 5. Assume simple number for the serial numbers for the sheet of tickets: 0,1,2,3. Here we show the tokens of bidder 0 and 1.
For n people and so on.

The Design:

Let’s design the smart contract for this. Visualize the situation using the screen shot given below.

Example

These are the pictures of items, we need to define “Items” in the smart contract. We will also need to define Persons or bidders who will bidding on the Items. We will also need some supporting data variables.

The functions are similar to the Ballot of our lessons. Constructor that initializes the owner, register that allows (decentralized person) to register online to get the tokens and start bidding, bid function that lets a person bid, and finally revealWinner, to randomly choose the winner for the item auctioned. Here is our design. Always remember to design first. The Auction smart contract has Item and Person structs and other data items such as array of Items, array of Persons, array of winners, mappings, and beneficiary address.

The Design

Implementation:

You will write two versions of the implementation templates: version 1: without modifier (80%) and version 2 with modifier (20%). We have provided the templates for both versions.

  1. Please understand the problems before you proceed.
  2. Copy the template into your Remix IDE. Complete the code. You will need to fill in the code at *ONLY* at the locations indicated. Test it to see if it is operational.
  3. 3. Implement version of as Auction.sol and submit for grading. Then update this base version for Auction.sol for Part 2 requirements, and submit for grading.

Version 1: (80%) Auction.sol: There are 6 tasks where you will fill in the code. You need to review the code given and understand it fully before you start adding code. This partial code is available in the course resources section as Auction.sol.

Testing on Remix:

Test the completed code by compiling and running it on Remix JavaScript VM. (i) Account 0 provided by JavaScript VM is the Auction beneficiary and will not bid. (ii) Navigate to each of the other accounts, and “register.” You will register four bidders using register function. (iii) The next step is for the bidders to each bid; for test purposes, you can execute the “bid” function with {{0,1}{1,1}{2,1} } for each of the four accounts. (iv) Next, execute the “revealWinner” function to determine the winner for each item randomly, and (v) the getter of the “winners” data can be executed with {0, 1 and 2} as a parameter in sequence to reveal the winners of the draw respectively. You can do a lot of more testing and exploration with the buttons provided by the Remix web interface. Partial code for Auction.sol

Partial code for Auction.sol

Complete code Auction.sol:

Key takeaways.

--

--

Sigit H. Yudanto

⛓️ Blockchain Basic Certified (Coursera) University at Buffalo & State University of New York. ✉️ Inquiry: hello[at]sigit.co.uk