1

I am trying to solve the problem of contract access and I understand from the very informative documentation that owner should be assigned to msg.sender by a constructor when the contract is created. Does that mean the original account which deployed the contract is then the owner? How does that relate to tx.origin?

How secure of the msg.sender test and can this be extended to for example securing a function for a set of approved accounts also stated when the contract is created in the constructor?

I also saw payable not stated in the following example. Is that because constructors do not need payable when updating a state variable?

Code example -

pragma solidity ^0.4.0;

contract Coin {
// The keyword "public" makes those variables
// readable from outside.
address public minter;
mapping (address => uint) public balances;

// Events allow light clients to react on
// changes efficiently.
event Sent(address from, address to, uint amount);

// This is the constructor whose code is
// run only when the contract is created.
function Coin() public {
    minter = msg.sender;
}

function mint(address receiver, uint amount) public {
    if (msg.sender != minter) return;
    balances[receiver] += amount;
}

function send(address receiver, uint amount) public {
    if (balances[msg.sender] < amount) return;
    balances[msg.sender] -= amount;
    balances[receiver] += amount;
    Sent(msg.sender, receiver, amount);
}
}
  • 1
    Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. – eth Feb 18 '18 at 6:51

Browse other questions tagged or ask your own question.