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{
    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);


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

        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) {
            blindedBid: _blindedBid,
            deposit: msg.value

    function reveal(
        uint[] memory _values,
        bool[] memory _fake
        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))) {
            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) {
        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.

i also try to get help from here.

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 -

Hope this helps. :slight_smile:


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