Go-ethereum private network in Proof-of-Authority问题:调用合约方法但没有响应

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

当我使用 POA 共识创建一个 2 节点私有网络时,当我发送一个简单的 t运行saction 时它工作正常。 但是当我用 Truffle 部署一个简单的合同 SimpleStorage.sol 时,我想使用 myetherwallet 调用 get() 方法,但它 returns 0 ,而不是 100.

SimpleStorage详情如下:

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;
    }
}
系统信息
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
重现行为 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 启动命令
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 设置

松露-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"
      // }
    }
  }
}

迁移脚本

truffle migrate --network geth --reset
预期行为

调用get()方法时,应该return100.

实际行为

return编辑了0

我发现还有一个 运行 和我有类似的问题: One of ethereum solidity methods is not working properly got error Returned values aren't valid, did it run Out of Gas

谁能帮我解决这个问题?谢谢。

我已经弄清楚为什么我无法从变量 storedData...

中检索值

当我将 storedData 设置为 public 时,它会正常工作。

(但需要注意的是,如果使用 ganache-cli,我可以获得 storedData,即使它不是 public 变量...)

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