1

Say I have one contract:

contract Token {
    uint totalSupply;

    function Token() public {
        totalSupply = 0;
    }

    function mint() public{
        //Do minting
    }
}

And then an another contract where the first contract is a public variable:

contract CrowdSale {

    Token public token;

    function Test() public{

    }

    function buyTokens() external payable {
        token.mint();
    }
}

What I want to know if the mint function of the Token is accessible from the outside? When I tried to do it in Remix, I only got "0": "address: 0x0000000000000000000000000000000000000000" from the public token, but is there a way to call the mint function or is it actually secure and people will only able to call the buyTokens function?

1

Well, based on the signature of your mint() function, people will be able to call it directly, interacting with the token contract directly.

Usually, projects who do ICOs tend to do the token and crowdsale in one contract. If you don't want to do that, you can make it so only your crowdsale contract can call the function by restricting its access.

contract Token {
    uint totalSupply;
    address crowdsaleContract;

    function Token() public {
        totalSupply = 0;
    }

    function mint() public{
        require(msg.sender == crowdsaleContract);
        //Do minting
    }
}

Another option would be to mint the tokens beforehand, and credit your crowdsale address with them, so you can distribute them directly.

P-S : You should use battle-tested contracts for this kind of stuff, instead of making your own. You could use Zeppelin's contracts. I am not affiliated with them.

  • Well I guess extending the contract seems the best solution and making mint internal, I'm using the zeppelins Token contracts, but their crowdsale one doesn't fit our requirements so I only use it as an example, hence why I ended up in this situation. – Vladislav Achramovic Apr 3 '18 at 9:25

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.