I have just started implementing ownership checks in my code. I used the code:

contract owned {
    constructor() public {
        owner = msg.sender;
    address public owner;

Then inherited it with "is owned".

When trying to create a contract from another contract I get a transaction error. I changed nothing else other than a test to see if the owner was requesting the creation:

    if (msg.sender != owner)

Does adding "is owned" require additional gas? Any ideas what could be wrong? I am not quite sure how to solve this. Any idea?

  • Yes, adding a new inheritance costs gas upon deployment as the new constructor needs to be executed. Otherwise difficult to say what your transaction problem is unless you provide more code. – Lauri Peltonen Aug 4 at 8:55
  • I changed nothing else other than a test to see if the owner was requesting the creation - where exactly have you added this test? I don't see it in your code! – goodvibration Aug 4 at 9:03
  • Adding is Owned will slightly increase the gas cost of course, but that doens't sound like the problem that you're dealing with. To me it sounds like the transaction reverts simply because the msg.sender is the caller contract, and not the owner of that contract (i.e., not the account that you've used for deploying that contract). – goodvibration Aug 4 at 9:08
  • Thanks both, for your comments. @goodvibration what you say makes sense. I think you are right. However, how can I make sure that only the owner OR a caller contract created by the owner is calling the function in question? – Philip Rutovitz Aug 5 at 3:59
  • How am I supposed to answer this question without the relevant code??? – goodvibration Aug 5 at 4:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.