Building A Blind Auction

i was trying to do blind auction tutorial, even I checked everything many times, I could not find to solution.I can not call pending returns function, is there something wrong with my codes ? Thank you

pragma solidity >=0.7.0 <0.9.0;
contract BlindAuction{
    // VARIABLES
    struct Bid {
        bytes32 blindedBid;
        uint deposit;
    }

    address payable public beneficiary;
    uint public biddingEnd;
    uint public revealEnd;
    bool public ended;

    mapping(address => Bid[]) public bids;

    address public highestBidder;
    uint public highestBid;

    mapping(address => uint) pendingReturns;

    
    // EVENT

    event AuctionEnded(address winner, uint highestBid);

    // MODIFIERS

    modifier onlyBefore(uint _time) { require(block.timestamp < _time); _; }
    modifier onlyAfter(uint _time) { require(block.timestamp > _time); _; }
    
    // FUNCTIONS

    constructor(
        uint _biddingTime,
        uint _revealTime,
        address payable _beneficiary
    ){
        beneficiary = _beneficiary;
        biddingEnd = block.timestamp + _biddingTime;
        revealEnd = biddingEnd + _revealTime;

    }
    
    function generateBlindedBidBytes32(uint value, bool fake) public view returns (bytes32) {
        return keccak256(abi.encodePacked(value, fake));
    }
    
    function bid(bytes32 _blindedBid) public payable onlyBefore(biddingEnd) {
        bids[msg.sender].push(Bid({
            blindedBid: _blindedBid,
            deposit: msg.value
        }));

    }
    
    function reveal(
        uint[] memory _values,
        bool[] memory _fake
    )
        public
        onlyAfter(biddingEnd)
        onlyBefore(revealEnd) 
    {
        uint length = bids[msg.sender].length;
        require(_values.length == length);
        require(_fake.length == length);

        
        for (uint i=0; i<length; i++) {
            Bid storage bidToCheck = bids[msg.sender][i];
            (uint value, bool fake) = (_values[i], _fake[i]);
            if (bidToCheck.blindedBid != keccak256(abi.encodePacked(value, fake))) {
                continue;
            }
            if(!fake && bidToCheck.deposit >= value) {
               if (!placeBid(msg.sender, value)) {
                   payable(msg.sender).transfer(bidToCheck.deposit * (1 ether));
               }
            }
            bidToCheck.blindedBid = bytes32(0);
        }
        
    }
    
    function auctionEnd() public payable onlyAfter(revealEnd) {
        require(!ended);
        emit AuctionEnded(highestBidder, highestBid);
        ended = true;
        beneficiary.transfer(highestBid * (1 ether));

    }
    
    function withdraw() public {
        uint amount = pendingReturns[msg.sender];
        if (amount > 0){
            pendingReturns[msg.sender] = 0;

            payable(msg.sender).transfer(amount* (1 ether));
        }

    }

    function placeBid(address bidder, uint value) internal returns(bool success) {
        if (value <= highestBid) {
            return false;
        }
        if (highestBidder != address(0)) {
            pendingReturns[highestBidder] += highestBid;
        }
        highestBid = value;
        highestBidder = bidder;
        return true;
    }
}

Hey @aliekber1976

Please share the error message and tutorial link.

problem is, when I deployed my contract and start new auction , I can not see pending returns on the left side.

https://www.youtube.com/watch?v=TGJ1WLLw9ic&t=687s

i also try to get help from here.

https://docs.soliditylang.org/en/v0.8.3/solidity-by-example.html#simple-open-auction

1 Like

Hi @aliekber1976,

This is because the instructor made the pendingReturns variable as public to test and show you how the functionality works. Ideally, pendingReturns should not be public and should work behind the scenes. It was made public just to show you how it operates. The instructor must’ve forgotten to mention it in the video.

You can find the change in the code at minute 21:01 in the video - https://www.youtube.com/watch?v=TGJ1WLLw9ic&list=PLFPZ8ai7J-iTJDENUIY40VsU_5Wmxkr7j&index=12

Hope this helps. :slight_smile:

2 Likes

yes thank you so much I understand now. I did not listen until the end because I thought I make a mistake somewhere and I was struggling with that , my fault :slight_smile:

1 Like

Where can I find the source code for the tutorial? Thank you

nm, I got it :slightly_frowning_face:

Is there a frontend available somewhere?
Or which tutorial would be the closest to follow to build a frontend (that requires authentication and talk to the smartcontract)?
Thank you