Calling contract method via Factory contract

roniehronieh Member Posts: 1

I have a query regarding calling a contract method via a second contract.

I have the following basic contracts as below.

Factory creates a Contract and stores it's address. It has a getTheContract() method to return the address of the stored contract.
Contract stores a single variable and has a getTheVar() method which returns that variable.

What I assumed I could do is to access the getTheVar() method through the address stored in Factory using web3 call(). Such as the following call:

While returns the address as expected, the further call to getTheVar throws an error ( TypeError: Cannot read property 'call' of undefined )
I assume because it does not like the method chaining.

What I was hoping to understand is whether this is possible? [ Adding a getTheVar() method to Factory, which then calls Contract(theContract).getTheVar(), works fine, but I wanted to call directly from the address ]

contract Contract { uint theVar; function Contract(uint iVar) { theVar = iVar; } function getTheVar() constant returns ( uint ) { return theVar; } } contract Factory { address public theContract; function createContract(uint iVar) public { theContract = new Contract(iVar); } function getTheContract() constant returns ( address ) { return theContract; } }

Sign In or Register to comment.