- Truffle Quick Start Guide
- Nikhil Bhaskar
- 103字
- 2021-06-25 20:47:34
Adding an owner
It's a good idea to have an owner of a contract and give them the sole right to perform admin-level actions such as the rewarding of a doer, so let's define and set an owner:
pragma solidity ^0.4.17;
contract TaskMaster {
mapping (address => uint) public balances; // balances of everyone
address public owner; // owner of the contract
function TaskMaster() public {
owner = msg.sender;
balances[msg.sender] = 10000;
}
}
The owner of the contract is set to msg.sender, the address instantiating the contract. You will learn more about msg.sender and other Solidity special variables in the next chapter.