1

I am using Zeppelin OS to create a migratable contract MyContract, which will be imported into another contract Foo. Foo calls the baz() function of MyContract, so when MyContract is upgraded, Foo should be calling the upgraded code automatically.

MyContract.sol

pragma solidity ^0.4.18;
import 'zos-lib/contracts/migrations/Migratable.sol';

contract MyContract is Migratable {
    uint256 public x;

    function initialize(uint256 _x) isInitializer("MyContract", "0") public {
        x = _x;
    }

    function baz() public returns (uint256) {
        decrement();
        return x;
    }

    function increment() public {
        x += 1;
    }

    function decrement() public {
        x -= 1;
    }
}

Foo.sol

pragma solidity ^0.4.18;

import './MyContract.sol';

contract Foo {
    uint256 public x;
    MyContract myContract;
    address myContractAddress;

    constructor(address _myContractAddress) public {
        myContractAddress = _myContractAddress;
    }

    function baz() public {
        myContract = MyContract(myContractAddress);
        x = myContract.baz();
    }
}

I am deploying MyContract and its proxy by running

zos add MyContract
zos push --network local
zos create MyContract --init initialize --args 42 --network local

How can I deploy Foo.sol?

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.