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:

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();
  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:

error log

Any ideas of what I am doing wrong?


  • You're not sharing your contract's code. That's definitely wrong in terms of posting your question here, when this information is required in order to address it. Commented Jul 12, 2020 at 18:30
  • Hi, I added the function code. Do you need the full code? I already tested the contract in Remix and with Truffle test and works fine. I think the problem is something related to how I connect to the agent instance or how I call the get function in terms of connectivity.
    – gilvictor
    Commented Jul 12, 2020 at 19:43

2 Answers 2


The get function must include .call(), maybe that is the problem


Check your compiled contract abi JSON representation. Most probably getAgentDetails() is missing in the abi. Remove any default network in your environment and set the test net address properly and compile again. It should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.