I'm writing a smart contract where subscribers make a bid, post doing so owner selects one and sends him data as well as ends the contract. If data is valid, winner releases the funds so owner can withdraw them.

My issue here is I'd like upon contract closure, that only other subscribers not the winner to be able to withdraw their funds however, not the winner as well as the owner.

Post release the owner can claim his funds.

Any ideas how to do so.

function done() onlyOwner public{
    require (state == State.Active, "Contract still working.");
    state = State.WinnerSelected;

function withdraw() external onlyOwner payable{
    require (state == State.WinnerSelected, "Contract not closed to withdraw.");

function release() public {
    require(payments[msg.sender] > 0, 'Sender has not paid into escrow.');
    require(released[msg.sender] == 0, 'Sender has already released funds.');
    released[msg.sender] = payments[msg.sender];
    //state = State.WinnerSelected;

function makeBid(string memory _extraData) public inState(State.Active) payable returns(uint bidIterator) {
    require(msg.value > 0, "No value inserted");
    require(bidders <= 3, "Contract reached max registrations");
    require(payments[msg.sender] == 0, 'Sender previously paid into escrow.');
    bids.push(Bid(msg.sender, msg.value, _extraData, true));
    payments[msg.sender] = msg.value;
    bidders ++; 
    //if (bidders < 4){
    // state = State.closed;
    return bids.length - 1;
  • 1. The description at the top of the question is extremely unclear IMO. Jul 4, 2019 at 7:56
  • 2. The message "Contract still working." should in fact be "Contract no longer working.". Jul 4, 2019 at 7:56
  • 3. The message "Contract not closed to withdraw." is confusing IMO. It should probably be "Contract not yet opened for withdrawals." or something similar. Jul 4, 2019 at 7:58
  • 4. In owner.transfer((address(this).balance)); you'll be transferring all o the funds in the contract to owner. I'm pretty ure that this is not your actual intention (and I'm petty sure that I've already mentioned that in a comment to an earlier question of yours). Jul 4, 2019 at 7:59
  • 5. At the end of function release(), I believe that you should do payments[msg.sender] = 0;., though I cannot be sure, because you don't seem to do anything with the variable released. Jul 4, 2019 at 8:00


Your Answer

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

Browse other questions tagged or ask your own question.