trufflesuite/drizzle-legacy

Contract inheritance and public methods

Closed this issue · 6 comments

Hey guys,

First off, thanks for Truffle and Drizzle, these tools are awesome!

I feel like this is a noob question, but since I've exhausted all the google searches and Solidity docs I decided to post it here. Here it goes:

I have a main contract A I'm deploying that inherits from another contract B. I setup a react project to work with Drizzle using the truffle box. I can access the main contract and I can see its direct methods, however, the public methods inherited from Contract B are not present. Is this expected behaviour ? From what I can see in the Solidity docs on inheritance, those should be exposed as well.

Here's a simplified view of the contracts

pragma solidity ^0.4.18;

contract ContractA {
  struct Object {
    bytes32 code;
    address owner;
  }

function createObject(...) public {
}
pragma solidity ^0.4.18;

import './ContractA.sol';

contract ContractB is ContractA {
function balanceOf(...) {}

I'm migrating just ContractB and that's the ABI I'm loading in the React / Drizzle app. I'm attaching the contract to the window object to try test it out. Drizzle get initialized and I can see the auto-completed methods, ContractB does not list createObject like I would expect.

Thanks in advance!

I am seeing that only view and pure functions are accessible. Anything that is payable or changes state is not exposed.

Is this intentional?
This means to call those functions you'll need to use the web3 standard Contract interface

I second @klivin's observation. Why are Smart Contract calls that change state not exposed via Drizzle?

Those functions are exposed, but will not appear as keys in the store. For state mutations, see the documentation on cacheCall(). Please comment if I'm missing something.

@tzumby That's odd. Just checked with a token contract that inherits from a base and I see functions from derived contracts. Does the artifact file contain all the expected functions?

@DiscRiskandBisque it's been a while, I can test this out again when I get a chance.

@tzumby,

I was unable to reproduce and will close this out. Please reopen if it is still a problem.

For anyone following up on this - I tested with the code below and was able to view baseOwner, baseValue and setBaseValue in the derived contract.

pragma solidity >=0.4.21 <0.6.0;

contract Base {
    address private owner = msg.sender;
    uint base_value;

    function baseOwner()
    public view
    returns(address) { return owner; }

    function isOwner(address location)
    public
    returns(bool) { return location == owner; }

    function setBaseValue(uint value)
    public { base_value = value ;}

    function baseValue()
    public view
    returns(uint) { return base_value; }
}

contract SimpleStorage is Base {
    uint public storedData;

    function set(uint x) 
    public { storedData = x; }
}