I have created an EnergyExchange
contract in my React app.js that it is deployed in the network.
Inside the EnergyExchange
contract there is a function to create Agent
contracts.
What I am trying to do is store the instance of the Agent
contract somewhere in the EnergyExchange
contract so whenever I want I can retrieve its instance and interact with him within my React web.
I was thinking on doing something like this:
pragma solidity ^0.4.24;
import "./Ownable.sol";
import "./Agent.sol";
contract EnergyExchange is Ownable{
struct Info {
Agent ainstance;
}
mapping (address => Info) public contractInstance;
function addAgentContractInstance(Agent _contractInstance) public{
contractInstance[msg.sender].ainstance = _contractInstance;
}
function getAgentContractInstance() public view returns (Agent){
//return contractInstance[msg.sender];
return contractInstance[msg.sender].ainstance;
}
}
But i am getting the following error when calling the functionlike this in React:
let agentInstance = await AgentContract(this.web3.currentProvider,this.exchange.address,this.state.account);
await this.exchange.addAgentContractInstance(agentInstance,{from:this.state.account});
Error:
Uncaught (in promise) Error: Invalid number of arguments to Solidity function
The instance object is causing this error can be seen next:
AgentContract
(whose code you haven't provided in your question).