0

When I try and complie the following code:

pragma solidity ^0.4.18;

contract mortal{

    address owner;

    function mortal(){

        owner = msg.sender;
    }

    modifier onlyOwner{

        if (msg.sender != owner){
            throw;
        }
    }

    function kill() onlyOwner{

        suicide(owner);
    }
}

I get the warning:

No visibility specified. Defaulting to "public". function mortal(){

^ Spanning multiple lines.

I am sure this is a very basic newbie error but I would appreciate your help!

Thanks,

Phil

2

That's not an error. It's a warning that the default visibility is public.

I'd suggest you make the visibility explicit:

function mortal() public {
1

Alright, so I was able to figure this out. Instead of Throw I should have used revert() and instead of suicide() I should have used selfdestruct. The code now looks like:

contract mortal{

address public owner;

function mortal() public {

    owner = msg.sender;
}

modifier onlyOwner{

    if(msg.sender == owner) { 
        revert();
    }else{
        _;
    }
}

function kill() onlyOwner public {

    selfdestruct(owner);
}

}

Many thanks for your help again!

0

As well as the previous suggestion by smarx. You need to put a _ somewhere in modifier onlyOwner to specify where the code it modifies will run. Then it should compile.

Eg it should probably look like this:

modifier onlyOwner{
    if (msg.sender != owner){
        throw;
    }
    _;
}
  • Thanks both. I am one step further but there is still one error in the code. contract mortal{ address public owner; function mortal() public { owner = msg.sender; } modifier onlyOwner{ if (msg.sender != owner){ throw; }else{ _; } } function kill() onlyOwner{ suicide(owner); } } I now get the error that it will not compile because throw is deprecated: "throw" is deprecated in favour of "revert()", "require()" and "assert()". throw; ^---^ Any ideas what this could be? Thanks a million for your help. – Philip Rutovitz Jan 18 '18 at 5:08

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.