I am trying to call a contract from another contract.
first contract is the source of items like a data table.
second contract is like a logic layer for the items.
I first deployed the contract1 and got the address, it is working fine.
When I tried to deploy the second contract which has the variable of type contract1 it is throwing the below error when compiling
Error: Identifier not found or not unique.
below is my second contact code
contract itemlistcallercontract {
ItemListContract itemlistcontract;
function itemlistcallercontract()
{
itemlistcontract = ItemListContract("0x16c5d0c8fccaf7e5824f5ae25c1662877cec6452");
}
function getitemcount() constant returns(int count)
{
return itemlistcontract.countItemList();
}
}
i am trying to take the reference of contract1 by passing its address in the contract2 constructor.
But the error is thrown in the declaration of the itemlistcontract variable it self.
Cant we call a contract deploying them seperately?
Is there any point I am missing here?
Best Answer
I refer to your code for
ItemListContract
in Unable to add new struct item into mapping or array.The following code compiles without errors:
In your code, the compiler will need to know the code for
ItemListContract
. The address for the first contract is defined without the double quotes. I also had to change thegetItemCount()
return type to match that ofItemListContract.countItemList()
.You can also just provide the interface for the first contract without the implementation details as shown below: