0

I was looking at the simple open auction example from the solidity docs. I don't understand the withdrawal part where a previous bidder wishes to withdraw his funds after he has been over bid.

This is an excerpt from the code.

/// Withdraw a bid that was overbid.
function withdraw() public returns (bool) {
    uint amount = pendingReturns[msg.sender];
    if (amount > 0) {
        // It is important to set this to zero because the recipient
        // can call this function again as part of the receiving call
        // before `send` returns.
        pendingReturns[msg.sender] = 0;

        if (!payable(msg.sender).send(amount)) {
            // No need to call throw here, just reset the amount owing
            pendingReturns[msg.sender] = amount;
            return false;
        }
    }
    return true;
}

How are the funds returned? Or is the process facilitated by some other way?

0

The funds are returned by this line

payable(msg.sender).send(amount)

where msg.sender will receive amount.

2
  • I think I understand, the if the condition will execute, if it fails the pendingReturns amount will return to the additional deposit. This syntax is new to me! Mar 28 at 19:45
  • @ArjunBhobe That's correct. The function send() returns false when the transfer has failed.
    – Ismael
    Mar 28 at 19:52

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.