I am learning Solidity and contract development but I am a little confused about how to go about structuring the contracts. I know that I am going to divide the code instead of 1 large contract but I am unsure as to what approach to take.

I have been looking at inheritance but I am a little unsure as to what this entails for upgrades/updates. I was told that inheritance creates 1 large contract, would this mean that when I update 1 inherited contract they all get updated and thus lose the state/data?

Another approach that I quite like is injection, I am guessing that this approach will reduce transaction costs as I can update contracts independently of others, is this correct?

Obviously this would require managing the address locations. See below for an example I found here

pragma solidity ^0.4.6;

contract Caller {
    function someAction(address addr) returns(uint) {
        Callee c = Callee(addr);
        return c.getValue(100);

    function storeAction(address addr) returns(uint) {
        Callee c = Callee(addr);
        return c.getValues();

    function someUnsafeAction(address addr) {
        addr.call(bytes4(keccak256("storeValue(uint256)")), 100);

contract Callee {
    function getValue(uint initialValue) returns(uint);
    function storeValue(uint value);
    function getValues() returns(uint);

Any advice on what approach to take would be great, thanks.

1 Answer 1


Inheritance is done at compile time.

would this mean that when I update 1 inherited contract they all get updated and thus lose the state/data?

It's unclear what you mean by "update." Once deployed, a smart contract is immutable. All you can do is call functions on the contract. But each contract is independent... the inheritance you did when you wrote and compiled the contract is gone by the time it's deployed.

Injection can be done, but I'm not sure I understand the scenario in the example you gave. Is this just some sort of convenience layer? The caller is specifying the address, so why wouldn't they just call the "Callee" contract directly?

Multiple Parity multisig bugs involved this sort of delegation to another contract. I would advise against it and recommend just using inheritance.

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.