Search code examples
ethereumsolidityweb3jstrufflego-ethereum

Go-ethereum private network in Proof-of-Authority problem: call contract method but nothing response


When I created a 2 nodes private network with POA consensus and it works fine when I sent a simple transaction. But when I deploy a simple contract SimpleStorage.sol with Truffle, I want to call the get() method by using the myetherwallet, but it returns 0 , not 100.

The detailed of SimpleStorage is as shown below:

pragma solidity >=0.4.17;

contract SimpleStorage {
    uint storedData = 100;

    function set(uint x) public {
        storedData = x;
    }

    function get() public view returns (uint) {
        return storedData;
    }
}

System information

Geth Version: 1.8.23-stable
Git Commit: c942700427557e3ff6de3aaf6b916e2f056c1ec2
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.11.5
Operating System: darwin (MacOs)
GOPATH=
GOROOT=/Users/travis/.gimme/versions/go1.11.5.darwin.amd64

Truffle v5.0.7 (core: 5.0.7)
Solidity v0.5.0 (solc-js)
Node v9.10.0

Behavior to reproduce

Genesis.json
{
  "config": {
    "chainId": 1515,
    "homesteadBlock": 1,
    "eip150Block": 2,
    "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "eip155Block": 3,
    "eip158Block": 3,
    "byzantiumBlock": 4,
    "clique": {
      "period": 2,
      "epoch": 30000
    }
  },
  "nonce": "0x0",
  "timestamp": "0x5d5769ad",
  "extraData": "0x00000000000000000000000000000000000000000000000000000000000000003b50d35ed4032c984992ad0d757ba65338523919fc0f1c754a2dfa18640ce2a0950aea20d1d206940000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "gasLimit": "0x7FFFFFFFFFFFF",
  "difficulty": "0x1",
  "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x0000000000000000000000000000000000000000",
  "alloc": {
    "3b50d35ed4032c984992ad0d757ba65338523919": {
      "balance": "0x200000000000000000000000000000000000000000000000000000000000000"
    },
    "fc0f1c754a2dfa18640ce2a0950aea20d1d20694": {
      "balance": "0x200000000000000000000000000000000000000000000000000000000000000"
    }
  },
  "number": "0x0",
  "gasUsed": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
Geth start command
geth --datadir node1/ --syncmode 'full' --port 30312 --rpc --rpcaddr 0.0.0.0 --rpcport 8502 --rpccorsdomain "*" --ws --wsaddr 0.0.0.0 --wsport 8602 --wsorigins "*" --rpcapi admin,db,eth,debug,miner,net,shh,txpool,personal,web3 --wsapi admin,db,eth,debug,miner,net,shh,txpool,personal,web3 --bootnodes 'enode://4765bd12afddce5bb5a2ea55e58ffcdbade132a593bddd9f2723e18460b407039bf07e3fa851b12b0b20c8e0b4c2d3518c9578f201b4efe6ab4d9243e28cccaa@127.0.0.1:30310' --networkid 1515 --gasprice '1' -unlock '0x3b50d35ed4032c984992ad0d757ba65338523919' --password node1/password.txt --mine --targetgaslimit 2251799813685247

Truffle set up

truffle-config.js


module.exports = {
  networks: {
    geth: {
      host: "127.0.0.1",
      port: 8501,
      from: "0xfc0f1c754a2dfa18640ce2a0950aea20d1d20694",
      network_id: "*",
      gasPrice: "0x47B7600",
      gas: "0x47B7600"
    }
  },

  // Set default mocha options here, use special reporters etc.
  mocha: {
    // timeout: 100000
  },
  // Configure your compilers
  compilers: {
    solc: {
      // version: "0.5.1",    // Fetch exact version from solc-bin (default: truffle's version)
      // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
      // settings: {          // See the solidity docs for advice about optimization and evmVersion
      //  optimizer: {
      //    enabled: false,
      //    runs: 200
      //  },
      //  evmVersion: "byzantium"
      // }
    }
  }
}

migration script

truffle migrate --network geth --reset

Expected behavior

When called get() method, it should return 100.

Actual behaviour

It returned 0

I found that there's another one ran into a similar issue as me:

One of ethereum solidity methods is not working properly got error Returned values aren't valid, did it run Out of Gas

Can anyone help me to address this issue?


Solution

  • I have figured out why I cannot retrieve the value from variable storedData...

    When I set storedData to be public, then it works fined.

    (But to be noticed that if using ganache-cli, I can get the storedData even if it is not public variable...)

    pragma solidity >=0.4.17;
    
    contract SimpleStorage {
        // uint storedData = 100;
        uint public storedData = 100; // set it to be public
    
        function set(uint x) public {
            storedData = x;
        }
    
        function get() public view returns (uint) {
            return storedData;
        }
    }