I have developed a EnergyExchange DApp in the Ganache local network with React that consist of one main contract "EnergyExchange". This main contract has a function to deploy new Agent contracts.
So what I do is to store the deployed agents contracts in a mapping so later on when I want to interact with them I call the next function:
let contractInstance = await this.getAgentInstance();
That function returns the specific agent instance associated to the account is being used in the browser with metamask. See below the console.log of the instance:
As you can see, the getAgentInstance() function is returning the desired output though with some errors.(Any idea of why?)
But I was not worried about the error till something else happened. After I retrieve the instance of the Agent contract associated to the account I am using in Metamask, I use it to interact with the contract. i.e next function modifies the EnergyExchange main contract data:
async agentCancelSellOffer(){
let contractInstance = await this.getAgentInstance();
await contractInstance.cancelAddedSellOrder(this.state.inputCancelSellOrderId,{from:this.state.account});
}
And that function is executed fine. See also another function that is executed fine after retrieving the agent instance:
async agentAddOffer(){
let contractInstance = await this.getAgentInstance();
await contractInstance.addSellOrder(this.state.inputUnitsOfEnergy,this.state.inputPricePerUnit,{from:this.state.account});
}
The problem comes when I add into the logic a get function:
async agentGetDetails(){
let contractInstance = await this.getAgentInstance();
console.log(contractInstance);
let details = await contractInstance.getAgentDetails({from:this.state.account});
console.log('function get agentdetails executed');
The App crashes again after the next step:
let details = await contractInstance.getAgentDetails({from:this.state.account});
The getAgentDetails function from the AgentContract is detailed next:
function getAgentDetails() public view isOwner returns(address,uint,uint,uint){
return (agentAddress,agentID,agentCreationDate,agentAvailableEnergyToSell);
}
The error is what follows:
Any ideas of what I am doing wrong?
Thanks,