0

I have created a contract that allows a function issue, the code as followed;

function Issue(uint256 _value) public  {
    balanceOf[msg.sender] += _value;            // Subtract from the sender
    totalSupply += _value;                      // Updates totalSupply

 }

I want to edit that only the creator of the contract can Issue more token. I tried changing the public to internal, but after changing that, I cannot find the Issue function.

My questions is how do I edit this to make the issue only available to the founder?

2

You need to keep track of the account that deployed the contract, and then you need to check msg.sender in your function to make sure it's the same account.

Here's an example from https://programtheblockchain.com/posts/2017/12/26/checking-the-sender-in-a-smart-contract/:

pragma solidity ^0.4.19;

contract TipJar {

    address owner;    // current owner of the contract

    function TipJar() public {  // contract's constructor function
        owner = msg.sender;
    }

    function withdraw() public {
        require(owner == msg.sender);
        msg.sender.transfer(this.balance);
    }

    // unchanged code omitted
}
3
  • thank you buddy! I have figured out from your example! very helpful! – Alan Li Jan 28 '18 at 8:31
  • one more quick question, how to run function TipJar() public { // contract's constructor function owner = msg.sender; } upon contract creation – Alan Li Jan 28 '18 at 8:43
  • 1
    The constructor is by definition run when you create the contract. It's the function with the same name as the contract. – user19510 Jan 28 '18 at 8:44

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.