1

I want to have one deployed contract with my data structure and all data and another separate contract with functions that calls the deployed contract. If i've understood things correctly, one should implement a abstract contract with the function signatures so that my caller contract knows how it should call the deployed contract? If so, should (can) I specify the state variables (the data structure) of the deployed contract?

Thanks!

1

You can go like that:

contract StorageInterface {
        bool public b;
        function set(bytes32 key, bytes32 value) public;
        function get(bytes32 key) public returns(bytes32);
    }

contract Storage is StorageInterface {

    address public owner;

    mapping(bytes32 => bytes32) private store; // key => value, simple store

    function set(bytes32 key, bytes32 value) public { // public has "external" covered
        store[key] = value;
    }

    function get(bytes32 key) public returns(bytes32) {
        return store[key];
    }

    // here we use the variable we got from the interface contract.

    function isFine() public view returns(bool) {
       return b;
    }   
}

The more restrictive interface does not allow it.

interface StorageInterface {
        // bool public b;
        function set(bytes32 key, bytes32 value) external;
        function get(bytes32 key) external returns(bytes32);
    }

contract Storage is StorageInterface {

    address public owner;

    mapping(bytes32 => bytes32) private store; // key => value, simple store

    function set(bytes32 key, bytes32 value) public { // public has "external" covered
        store[key] = value;
    }

    function get(bytes32 key) public returns(bytes32) {
        return store[key];
    }

    // here we use the variable we got from the abstract contract.

    // function isFine() public view returns(bool) {
    //   return b;
    // }   
}

Hope it helps.

Your Answer

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

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