I have two contracts, one is a Admin, other is subject. To keep things simple I am just including the functions that are invoked in the contracts relating to each other.
contract Subject {
uint public count = 0;
function increaseCount() returns newCount{
count ++;
newCount = count;
}
}
The subject contract has a counter that can be increased via a direct call from web3.js or from Master contract.
contract Master {
bool public isActive=false;
uint public num=0;
function changeState() returns bool newState{
isActive = !isActive;
newState = isActive;
}
function increaseSubjectCount(subjectAddr) returns uint newCount{
SubjectContract subjectContract = SubjectContract(subjectAddr);
newCount = ubjectAddr.increaseCount();
}
}
so a transaction is fired to Master contract (once it is made of course) along with sufficient amount of gas. This function then uses the gas to call increaseCount() function in the Subject contract which returns the new counter. This in turn gets returned by the Master contract via web3.js. The issue I face is if I use browser solidity to compile the Master contract, it throws an error saying SubjectContract parametre undefined. If I add both contracts and then compile the code, when I use
var myContract = web3.eth.contract(masterContract.abi);
won't this cause issues if the abi code includes that of subject and master contract together, but if I don't do this, compiler throws bunch of errors.
Another thing I have considered is using import statements before compilation, but not sure how to safely implement it. Please help out guys!
@VarunHow did you get theSubjectAddr? I am having trouble to import the contract bySubjectContract subjectContract = SubjectContract(subjectAddr);coz I want to it to get the the address by itself like usingSubject.deplyed().addressor something like this. – 11t Mar 10 '17 at 11:04subjectAddr, it is a parametre that you need to know before hand and pass it like a regular expression. – Varun Agarwal Mar 10 '17 at 19:28@VarunI meant that because I have both the contracts in the same*.solfile and I have to getsubjectAddrforSubjectContract subjectContract = SubjectContract(subjectAddr);. So is there a command which I can use in solidity so that I don't have to insert the contract address in truffle or web3. something like the.address– 11t Mar 10 '17 at 22:21SubjectContract subjectContract = SubjectContract(subjectAddr);was to reference an existing contract at a known address and inspect its values. So if there are 100 such contracts deployed, I want to be able to call each one separately and inspect its values fromMastercontract. If the contract address were not to be inserted, it defeats the purpose of my function. :) – Varun Agarwal Mar 11 '17 at 09:36addressof some other contract in that file. – 11t Mar 11 '17 at 10:44.solfile or not. In fact I think you mgiht not be able to access address of another contract if its in the same as file as the main contract. Please test this using browser solidity or a testnet, cause I am pretty sure you won't be able to. Let me know if you can though. – Varun Agarwal Mar 11 '17 at 15:23