我正在运行一个带有POA的私有ethereum区块链
geth --port 3000 --networkid 42 --datadir=./blkchain --maxpeers=5 --rpc --rpcport 8543 --rpcaddr 127.0.0.1 --rpccorsdomain "*" --rpcapi "eth,net,web3,personal,miner" --allow-insecure-unlock 2>>eth.log然后使用Web3js发送事务
let tx = {from:accounts[targetAccount],to:accounts[targetAccount],value: 0,gas: 100000, data:web3.utils.toHex(targetAccount)};
web3.eth.accounts.signTransaction(tx, keys[targetAccount]).then(signed => {
var tran = web3.eth.sendSignedTransaction(signed.rawTransaction);
tran.on('transactionHash', hash => {
console.log('write blockchain ', hash);
});
tran.on('error', console.error);
});然后来自geth控制台的miner.start()
一切都很好。
但是,当我再次启动geth时,如果没有--允许--不安全--解锁,就会出现挂起的事务:(eth.pendingTransactions.length > 0),而sendTransaction总是返回: Error:返回的错误:已经知道。
我不想用这个方法:-允许-不安全-解锁。有什么线索吗?非常感谢!!
(如果我重新开始-允许--不安全--解锁,它似乎又起作用了)
发布于 2020-07-27 12:00:30
尝试显式指定专用网络信息,如本例中的web3js文档:
web3.eth.accounts.signTransaction({
to: '0xF0109fC8DF283027b6285cc889F5aA624EaC1F55',
value: '1000000000',
gas: 2000000
common: {
baseChain: 'mainnet',
hardfork: 'petersburg',
customChain: {
name: 'custom-chain',
chainId: 1,
networkId: 1
}
}
}, '0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318')
.then(console.log);将公共对象的参数替换为私有块链的参数。
此外,还有一些评论:
https://ethereum.stackexchange.com/questions/85301
复制相似问题