Just some pretty high level questions here.

  • When is it best to include modifiers?
  • Are there any safeties needed to be placed on the initial contract creation function?
  • In the last function of my sample contract, the one that sends me money...should I have an onlyCreator modifier? (why should I care if other people pay the gas?)

    contract factory {
    address[] public newContracts;
    address public creator;
    function factory (){
        creator = msg.sender;  
    function create () payable returns (address){
        require(msg.value >= 1 * 1000000000000000000);
        return newContract;
    function withdrawFee() {

1 Answer 1

  1. Modifiers are great for any reusable code. They are also useful for keeping your code readable. If you have some complicated verification logic it is nice to abstract it away so that the body of your function is clear and concise.

  2. No. The constructor can only be called once - on initialisation. You need to make sure that you execute any initial setup then and there.

  3. It depends what you are trying to achieve. This function will transfer the contract balance to the creator only.. BUT anyone can call it. So anyone can make the contract send you the funds. If that is what you want, then no you do not need the onlyCreator modifier.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.