First time coding in Solidity

gxugxu Posts: 17Member
I wrote my first solidity contract ( See below ) and tried to run it on Mist, it compiles fine but doesn't execute. Anything wrong?

pragma solidity ^0.4.2;

contract SendBack{
event LogThis(address arg);
address public owner;
function SendBack(){
owner = msg.sender;
}
function Half(){
LogThis(msg.sender);
if(! msg.sender.send(msg.value/2))
throw;
}
function Double(){
LogThis(msg.sender);
if(!msg.sender.send(msg.value*2))
throw;
}
}

Comments

  • robhitchensrobhitchens Posts: 3Member
    Need to add payable to half() and double(). It's a common pattern to set owner and use it to provide elevated privileges but your contract isn't using for anything in particular, so not needed. For style, camel-case functions except for the constructor.

    pragma solidity ^0.4.2;

    contract SendBack{

    event LogThis(address arg);
    // address public owner;

    function SendBack(){
    // owner = msg.sender;
    }

    function half() payable {
    LogThis(msg.sender);
    if(!msg.sender.send(msg.value/2))
    throw;
    }

    function double() payable {
    LogThis(msg.sender);
    if(!msg.sender.send(msg.value*2))
    throw;
    }
    }

Sign In or Register to comment.