sun_dance
sun_dance

Reputation: 281

Can a Child contract change values of a parent contract in Solidity

If we have 2 contracts like so :

contract A {
  struct SampleA{
    uint id;
    bytes32 name;
    bytes32 toChange;
  }
  mapping (uint=> SampleA) public idToStruct;
}

contract B is A{
  function changeVar (bytes32 newVar) public {
    idToStruct[0].toChange = newVar;
  }
}

Can I update variable in Contract A from contract B like this? Is this possible in solidity, if not is there a workaround?

Upvotes: 2

Views: 953

Answers (1)

Petr Hejda
Petr Hejda

Reputation: 43591

Yes, you can modify properties of the parent contract, as long as the property is not private.

Docs: https://docs.soliditylang.org/en/v0.8.6/contracts.html#visibility-and-getters

Upvotes: 2

Related Questions