My question is a variation of this one (old question).
In contract Test, the variable myval is created. In contract Other, an instance of the Test contract is created, and I access the instance variable with the getter function.
However, what if I want to access the same instance from another contract, Other2? If I try to use the same instance name, testContract, an error is raised about undeclared identifier so it must be a visibility issue. I do not want to create a new instance of Test because at some point, the value of myval will change and I need to access its value from multiple contracts.
Is this possible?
Is there an easier way? Note, the structure of Other2 will be much different than Other, so I don't want to just create a child and inherit the same stuff from it.
pragma solidity ^0.4.18;
contract Test {
bool public myval;
}
contract Other {
Test public testContract;
function setAddress2() {
testContract = new Test();
}
function getVal() constant public returns (bool) {
return testContract.myval();
}
}
contract Other2 {
//what to put here?**
}
Testaddress and pasting it into theOtherconstructor? – Mat Oct 02 '23 at 15:30