0

I am trying to keep track of the number of bidders in my contract.

 function bid() public payable an_ongoing_auction returns (bool){
    uint oldval = bids[msg.sender];
    require(msg.value+oldval > highestBid,"You can't bid, Make a higher Bid");
    highestBidder = msg.sender;
    highestBid = msg.value+oldval;
    if(oldval==0)
        bidders.push(msg.sender);
    bids[msg.sender] +=msg.value;
    emit BidEvent(highestBidder,  highestBid);
    return true;
}

If I remove the if statement the code run fine, but I want to only push the my bidders array when there is a new bidder. I am using remix and get the error:

transact to MyAuction.bid errored: VM error: revert.
revert  The transaction has been reverted to the initial state.
Note: The constructor should be payable if you send value.  Debug the 
transaction to get more information. 

I am new to solidity so sorry if this is an easy answer, but I couldn't find anything on it.

1
  • 1
    can you explain what actually an_ongoing_auction modifier does? Feb 25 '19 at 4:45
0
  1. I can't really answer your question about the error based on the snippet. Would need to see the entire contract.

  2. Don't use an array. Just increment an integer instead if your sole purpose is keeping track of the number of bidders. Less expensive, more efficient. (Arrays in solidity are to be avoided.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.