0

I have a structure similar like this typical Factory.

contract Factory {
  bytes32[] Names;
  address[] newContracts;

  function createContract (bytes32 name) {
      address newContract = new Contract(name);
      newContracts.push(newContract);
  } 

  function getName (uint i) {
      Contract con = Contract(newContracts[i]);
      Names[i] = con.Name();
  }
}

contract Contract {
  bytes32 public Name;
  string public numberString;

  function Contract (bytes32 name) {
      Name = name;
  }

  function setNumberString (string time){
      numberString = time;      
  }
}

I added to this structure the function setNumberString and the variable numberString, with Web3 js i have defined this:

myContract = web3.eth.contract(ABIArray).at(contractAddress);
myContract.setNumberString(state, function(error, result){
 if(!error)
     console.log(result)
 else
     console.error(error);
 })

The ABIArray and contractAddress are of the "contract Contract" created, and when i try to call the function, i obtain this message in the browser of the Dapp:

Uncaught TypeError: myContract.setNumberString is not a function

When i try to do this with a normal contract i don't have any problem, what i'm doing wrong? Is possible to call the function of this created contract?

1

This may occur because setNumberString is not defined in your ABI.

Try using this

ABIArray=[{"constant":false,"inputs":[{"name":"time","type":"string"}],"name":"setNumberString","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"Name","outputs":[{"name":"","type":"bytes32"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"numberString","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"inputs":[{"name":"name","type":"bytes32"}],"payable":false,"type":"constructor"}];
2
  • Nice fixed it, my ABIArray was wrong. I can acces to string public numberString; ? with myContract.numberString? or i need to modified the ABI array again? – Gawey May 26 '17 at 14:02
  • 1
    access it with myContract.numberString() – Badr Bellaj May 26 '17 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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