2

I was making an auction system and I wanted to make sure that when someone bid higher the contract would return the money to the address of the previous bid.

pragma solidity >=0.4.22 <0.6.0;

contract simpleAuction{
    uint currentValue = 0;
    address buyer;

    function set() public payable{
        uint sent = msg.value;
        require(sent>currentValue, "Bid less than current value.");

        buyer.transfer(currentValue);

        currentValue = sent;
        buyer = msg.sender;
    }

    function winner() public view returns (address addressWinner, uint newValue){
        addressWinner = buyer;
        newValue = currentValue;
    }
}

The error is in the line buyer.transfer (currentValue); that in case transfer() only works for msg.sender.

  • I think buyer should be a payable address – Majd TL Sep 5 at 8:40
3

If you are using Solidity 0.5.0 or greater, you will need to make buyer a payable address. You can do this by adding payable to the buyer declaration:

address payable buyer;

  • 1
    Thank you! It worked – João Vitor Sep 6 at 20:33

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.