0

I am compiling the following code on solc & remix ide:

pragma solidity ^0.5.1;
    contract Signed1 {
        uint val= 0;
        function withdrawOnce(int amount) public returns (uint){
           revert();
        }
        msg.sender.transfer(uint(amount));
        transferred[msg.sender] = true;

    }

I got the following error:

D:\SolidityContractsSelf\Remix\From Remix Site\Integer Bugs>solc sign1.sol sign1.sol:7:24: Error: Expected identifier but got '(' msg.sender.transfer(uint(amount));

Can some body please guide me how to get rid of this error? Is revert() still used?

Zulfi.

1 Answer 1

1

no compile errors, but not the best code and way to do that

pragma solidity ^0.5.1;

contract Signed1 {
    uint val = 0;
    mapping (address => bool) transferred;

    function withdrawOnce(int amount) public returns (uint) {
        require(amount > 0, 'only postive amount');
        require(transferred[msg.sender] == false, 'withdraw only once');
        transferred[msg.sender] = true;
        msg.sender.transfer(uint(amount));
    }

}
6
  • No error now but what is transferred[...] array? Is it a built-in array? If not then where is it declared? How the initial value of transferred is false?
    – zak100
    Commented Jun 8, 2019 at 20:54
  • transferred is a mapping from address to boolean, declared above and the default value is false or null im not sure, you should test it
    – Majd TL
    Commented Jun 9, 2019 at 8:01
  • you should also also check if the contract has balance more than the amount
    – Majd TL
    Commented Jun 9, 2019 at 8:03
  • @MajdTL The default value of booleans is always false in Solidity. Also, null does not exist in Solditiy
    – Jesbus
    Commented Jun 9, 2019 at 8:05
  • good thnx :)@JesseBusman
    – Majd TL
    Commented Jun 9, 2019 at 8:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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