Ethereum Go以太坊专用网络中的权限证明问题:调用契约方法但无响应
当我创建了一个具有POA共识的2节点专用网络时,当我发送一个简单事务时,它工作正常。 但是当我使用Truffle部署一个简单的contract simplestreage.sol时,我想使用调用get()方法,但它返回0,而不是100Ethereum Go以太坊专用网络中的权限证明问题:调用契约方法但无响应,ethereum,solidity,web3,truffle,geth,Ethereum,Solidity,Web3,Truffle,Geth,当我创建了一个具有POA共识的2节点专用网络时,当我发送一个简单事务时,它工作正常。 但是当我使用Truffle部署一个简单的contract simplestreage.sol时,我想使用调用get()方法,但它返回0,而不是100 SimpleStorage的详细信息如下所示: pragma solidity >=0.4.17; contract SimpleStorage { uint storedData = 100; function set(uint x)
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()
方法时,它应该返回100
实际行为
它返回0
我发现还有一个遇到了和我类似的问题:
有人能帮我解决这个问题吗?谢谢。我已经弄明白了为什么无法从变量
storedData
中检索值
当我将storedData
设置为public时,它就可以工作了
(但需要注意的是,如果使用ganache cli,我可以获取storedData
,即使它不是公共变量……)
我已经找出了为什么无法从变量
storedData
中检索值
当我将storedData
设置为public时,它就可以工作了
(但需要注意的是,如果使用ganache cli,我可以获取storedData
,即使它不是公共变量……)
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;
}
}