2
votes

I have problem with smart contract development using solidity. i have two smart contracts such as Factory contract and Contract contract. Here is my code.

Contract Factory {
  address[] newContracts;

  function createContract(uint num) {
    address newContract = new Contract(num);
    newContracts.push(newContract);
  }

  function getContract() view public returns(address[]) {
    return newContracts;
  }

  function getNum(address _add) view public returns(uint) {
    return Contract(_add).getNum();
  }
}


contract Contract {
  uint public Num;

  function Contract(uint num) {
    Num = num;
  }

  function getNum() public returns(uint) {
    return Num;
  }
}

I create the Factory contract in private blockchain. I call the createContract and getContract function, it works normally but when i call the getNum function i can not get the number. Thank you for your answer!

the picture of smartcontract problem

1
Make getNum() a view. - Adam Kipnis
Have you tried repeating the steps? I can't recreate the problem you are having. If I copy paste your code to remix and execute it, it works as it should. - Fischa7
thank you for your answer ! I use it in Remix by JavaScript VM and Test network Ganache or TestRPC is work well but when i use it with Private network or Private blockchain using Geth it has this problem. - yoyo

1 Answers

2
votes

After some tests, please check whether you have byzantiumBlock: 0 in your genesis file. If not, please add it and regenerate your private chain. See my genesis file below.

{                                                                                                                              
   "config": {
      "chainId": 1994,
      "homesteadBlock": 0,
      "eip155Block": 0,
      "eip158Block": 0,
      "byzantiumBlock": 0
   },  
   "difficulty": "400",
   "gasLimit": "2000000",
   "alloc": {
   }   
}

After doing this, your code should work.