You can update a state variable, or you can make the function read-only (with constant
, view
or pure
), but you can't do both. I've upvoted three answers that say it differently and offer different approaches depending on what you need it to do.
pragma solidity 0.4.9;
contract DA {
address public da;
function DA() public {
da = msg.sender;
}
function setDa() public returns(bool success) {
da = msg.sender;
return true;
}
// getDa() is not really needed because da is made `public` near line 5, so function da() does the same.
function getDa() public constant returns (address){
return da;
}
function getMsgSender() public constant returns(address) {
return msg.sender;
}
}
Hope it helps.
msg.sender
in the variableda
, such function cannot be constant because your are modifying the contract state.return msg.sender;
?