Hi Community,
I cloned rariable with Moralis tutorial but I am stuck with this problem.I wanna add auction for dapp but I could not figure out how to do it. I watched also another tutorial from Moralis about auction , I tried that with ether remix that works perfectly but could not implement for my dapp.I am also in Ivan academy and still learning about programming.Thank you so much.
My GitHub link
this is my auction.
pragma solidity >=0.7.0 <0.9.0;
contract SimpleAuction{
address payable public beneficiary;
uint public auctionEndTime;
address public highestBidder;
uint public highestBid;
mapping(address => uint) public pendingReturns;
bool ended = false;
event HighestBidIncrease(address bidder, uint amount);
event AuctionEnded(address winner, uint amount);
constructor(uint _biddingTime, address payable _beneficiary){
beneficiary = _beneficiary;
auctionEndTime = block.timestamp + _biddingTime;
}
function bid() public payable{
if (block.timestamp > auctionEndTime){
revert("The auction has already ended");
}
if (msg.value <= highestBid){
revert("There is alreay a higher or equal bid");
}
if (highestBid != 0){
pendingReturns[highestBidder] += highestBid;
}
highestBidder = msg.sender;
highestBid = msg.value;
emit HighestBidIncrease(msg.sender, msg.value);
}
function withdraw() public returns (bool){
uint amount = pendingReturns[msg.sender];
if(amount > 0){
pendingReturns[msg.sender] = 0;
if(!payable(msg.sender).send(amount)){
pendingReturns[msg.sender] = amount;
return false;
}
}
return true;
}
function auctionEnd() public{
if (block.timestamp < auctionEndTime){
revert ("The auction has not ended yet");
}
if (ended){
revert("the function auctionEnded has already been called");
}
ended = true;
emit AuctionEnded(highestBidder, highestBid);
beneficiary.transfer(highestBid);
}
}