3

I have problem with smart contract development using Remix solidity in private blockchain by Geth. I have two smart contracts such as Factory contract and Contract contract.

I create the Factory contract and then I call the createContract and getContract function, it works normally but when i call the getNum function I can not get the number.

I run this code in Remix solidity by JavaScript VM and Test network by Ganache or TestRPC work fine but when i use it with Private blockchain using Geth it has this problem

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;
  }
}

the picture of smartcontract problem

0

In Contract add view-modifier to getNum

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

Your calls worked in ganache/testrpc/remix because the test EVM is synchronous in nature. I.e., you'll be able to get return values of transactions, since sendTransaction calls are executed instantly.

enter image description here

  • 1
    I add view modifier to getNum in Contract but it still work the same problem ! – yoyo Apr 25 '18 at 5:13
  • 1
    yes ! I put the address with double-quotes. – yoyo Apr 25 '18 at 5:35
  • I used the remix solidity with private blockchain using Geth not with JavaScript VM – yoyo Apr 25 '18 at 5:44
  • Sorry.. Safari reseted my connection to JavaScript VM due to http/https. Anyway, it works with Web3 Provider and geth node with Clique PoA. Everything is fine (see updated screenshot). – ivicaa Apr 25 '18 at 6:13
  • 1
    I think maybe I have problem to setup private blockchain by Geth. so do you know which way to setup private blockchain by Geth correctly. – yoyo Apr 25 '18 at 8:44

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.