I'm trying to inherit a function from the parent contract into child contract and its working fine in remix JavaScript VM. I did the following steps:
- Deployed the parent contract in remix JavaScript VM.
- stored some random values by executing the
storeValue
function from the parent contract - copied the address of the parent contract and instantiated it in child contract
Now if I call the
getValue
function from the child contract that is basically calling the getting stored value function from the parent contract, the output is an array of values and everything is working perfectly fine.
BUT
If I deploy both contracts on the private blockchain, I'm getting an empty array of values. I did following steps:
- started the private blockchain (geth client)
- Change the environment to Web3 Provider in the remix
- deploy the WEB3DEPLOY code from remix in private chain and copied the address of mined address from the private chain
- used the address to instantiate the parent contract in child contract
- repeated the process of deployment for the child contract
- feed the values using web3.py in python jupyter notebook
Now, if I directly call the function accountTx
from parent contract in the frontend, its working fine. But, if I call the inherited function getValue
from the child contract in the frontend, the result is an empty array.
So, the problem is that I'm unable to get the output of the function getValue
that is calling the function from another contract when deployed on a private chain. But its working fine in remix JavaScript VM.
Parent contract:
pragma solidity ^0.4.20;
contract Parent {
uint256[] values;
mapping (address => uint256[])transactions;
function storeValue(uint256 _value) {
transactions[msg.sender].push(_value);
}
function accountTx(address addr) constant returns(uint256[]) {
return (transactions[addr]);
}
}
Child contract:
pragma solidity ^0.4.20;
import './Parent.sol';
contract Child {
/* instantiating parent contract*/
Parent p = Parent(0x9dd1e8169e76a9226b07ab9f85cc20a5e1ed44dd);
function getValue() public view returns (uint256[]){
return p.accountTx(msg.sender);
}
}
I have created the instance of parent contract as a global because I do want to use it for some functions.
Am missing something like to declare the function as an external
?
Any guidance would definitely be appreciated, thanks.