GithubHelp home page GithubHelp logo

auction's Introduction

Auction

This is an implementation of an auction contract on Ethereum. It is meant to be used for demonstrating purposes in a teaching context. It will allow multiple people to interact with the same contract and see the mechanics of a smart contract.

Installation

Transactions will be sent through Metamask. See here for instructions to set up Metamask.

Sending transactions requires testnet ETH. We recommend deploying the contract on Rinkeby. You can acquire testnet ETH here.

Transactions can be seen in Etherscan.

Interface & Description

Public State Variables

  • address payable public owner: contract and auction owner
  • address payable public max_bidder: address that placed the highest bid
  • uint public max_bid_value: current highest bid value
  • uint public endtime: bids can no longer be placed after this time
  • mapping (address => uint) public bids: maps bidders to bid values

Constructor

  • The constructor is called each time a contract is deployed. It will set the state variables need for the contract and requires the following parameter:
  • Parameter uint duration_minutes: amount of time after current time until the auction is closed
  • Parameter uint starting_bid: Minimum biding value, defined by owner

place_bid()

  • This function, callable from every address, allows everyone to place a bid. The bid amount is attached as the message value.
  • The function requires that the message value is higher than max_bid_value and that the current time is smaller than the end of the action.
  • It sets the message sender as the max_bidder, the message value as the new max_bid_value and stores the sender/ amount combination in the mapping ‘bids’.
  • Update endtime if the bid is placed shortly before endtime.

withdraw()

  • This function allows everyone except the current the highest bidder and the owner to withdraw the funds sent.
  • These two exceptions are checked and that the address has enough funds to do this withdraw and still hold the max_bid_value.
  • First update the mapping and then call the transfer function to prevent reentrancy attack.

Owner_withdraw()

  • Allows owner to withdraw funds after action is finished, as the end time is reached.
  • Checks that endtime is reached and that there is a highest bid, then transfers funds to owner. Uses the owner state variable to identify owner.

raise()

  • If you are presently the highest bidder, you can rise the bid value by however much is sent as the message value.
  • Checks that message sender is current highest bidder.
  • Adds message value to the mapping and updates max_bid_value.

get_winner()

  • Allows everyone to get the address of the max_bidder after the auction has ended.

Usage

Deploying

The open tool Remix can be used to demonstrate the contract. Using the environment 'Javascript VM', everything will be local and the contract is not deployed onto the real Ethereum (testnet) Blockchain. Choosing the environment 'Injected Web3' allows deploying the contract onto the Ethereum testnet Rinkeby. This requires that an account is set up with testnet Ethereum as explained in Installation. Other users can than interact with the contract using Metamask.

Creating contract

First, we have to create a contract. Here we specify the duration in minutes and the starting_bid value. Creating contract

Place bid

Everyone is able to place a bid in this contract. When a user places a new highest bid, he becomes the max_bidder, the max_bid_value is his bid and everyone can see his bid.

Endtime

The endtime is given in unix timestamp format: Endtime

Contributing

This contract was created by the CMU Blockchain Group

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.