-
Notifications
You must be signed in to change notification settings - Fork 0
/
englishAuction.sol
47 lines (31 loc) · 906 Bytes
/
englishAuction.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
contract EnglishAuction{
address payable public seller;
uint256 public timeToEnd;
bool public running;
address public highestBidder;
uint public highestBid;
constructor(){
seller = payable(msg.sender);
}
function startAuction() public{
require(!running);
require(seller == msg.sender);
running = true;
timeToEnd = block.timestamp + 1 minutes;
}
function bid() public payable{
require(running);
require(msg.value > highestBid);
payable(highestBidder).transfer(highestBid);
highestBidder = msg.sender;
highestBid = msg.value;
}
function win() public{
require(running);
require(timeToEnd <= block.timestamp);
running = false;
seller.transfer(highestBid);
}
}