1

Imagine that there's a smart contract deployed which contains a number of sub-contracts like so:

pragma solidity ^0.5.0;

contract A {
   address contract = 0x6663130dDfF21E3BC963Ee902005223b9A202106;
   ...
   contract.doSomething()
}

contract B {
   address contract = 0x6663130dDfF21E3BC963Ee902005223b9A202106;
   ...
   contract.doSomethingElse()
}

Is it possible to extract the reference that both of them make to the same external contract so as not to duplicate the same code?

For example something like this:

pragma solidity ^0.5.0;

address contract = 0x6663130dDfF21E3BC963Ee902005223b9A202106;

contract A {
   ...
   contract.doSomething()
}

contract B {
   ...
   contract.doSomethingElse()
}

Is that valid?

UPDATE

contract Fruit {
    address thing = address(12345);
}

contract Apple is Fruit {
    function eat() external {
        thing.call("");
    }
}

contract Banana is Fruit {
    function eat() external {
        thing.call("");
    }
}

^is there a way to prove definitively that this uses less gas?

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.