【发布时间】:2019-10-24 23:15:44
【问题描述】:
我正在尝试通过将 1 个以太币从一个帐户发送到另一个帐户来创建交易。目前,我正在运行一个本地完全同步的奇偶校验节点。它在 EWF(Energy Web Foundation)的 Volta 测试网络上运行。实际上可以通过 Metamask 连接到该节点并发送一些 Ether,但是每当我尝试使用在 nodejs 应用程序中运行的 web3js 时,奇偶校验节点都会给出以下警告/输出:
2019-10-25 00:56:50 jsonrpc-eventloop-0 TRACE own_tx Importing transaction: PendingTransaction { transaction: SignedTransaction { transaction: UnverifiedTransaction { unsigned: Transaction { nonce: 1, gas_price: 60000000000, gas: 21000, action: Call(0x2fa24fee2643d577d2859e90bc6d9df0e952034c), value: 1000000000000000000, data: [] }, v: 37, r: 44380982720866416681786190614497685349697533052419104293476368619223783280954, s: 3058706309566473993642661190954381582008760336148306221085742371338506386965, hash: 0x31b4f889f5f10e08b9f10c87f953c9dfded5d0ed1983815c3b1b837700f43702 }, sender: 0x0b9b5323069e9f9fb438e89196b121f3d40fd56e, public: Some(0xa3fc6a484716b844f18cef0039444a3188a295811f133324288cb963f3e5a21dd6ee19c91e42fa745b45a3cf876ff04e0fd1d060ccfe1dab9b1d608dda4c3733) }, condition: None }
2019-10-25 00:56:50 jsonrpc-eventloop-0 DEBUG own_tx Imported to the pool (hash 0x31b4f889f5f10e08b9f10c87f953c9dfded5d0ed1983815c3b1b837700f43702)
2019-10-25 00:56:50 jsonrpc-eventloop-0 WARN own_tx Transaction marked invalid (hash 0x31b4f889f5f10e08b9f10c87f953c9dfded5d0ed1983815c3b1b837700f43702)
当我检查账户余额时,什么都没有发生。我尝试增加gasPrice,将'from'键/值对添加到txObject等。我还使用--no-persistent-txqueue启动了奇偶校验节点,这样它就不会缓存太多事务,正如建议的here .但这也没有改变任何事情。所以我仍然得到同样的错误并且交易没有通过。是什么导致了这个问题,我该如何解决?
web3.eth.getTransactionCount(from, (err, txCount) => {
const txObject = {
nonce: web3.utils.toHex(txCount),
from: from,
to: to,
value: web3.utils.toHex(web3.utils.toWei(val, 'ether')),
gas: web3.utils.toHex(21000),
gasPrice: web3.utils.toHex(web3.utils.toWei('60', 'gwei'))
}
// Sign the transaction
const tx = new Tx(txObject);
tx.sign(pk);
const serializedTx = tx.serialize();
const raw = '0x' + serializedTx.toString('hex');
// Broadchast the transaction to the network
web3.eth.sendSignedTransaction(raw, (err, txHash) => {
if (txHash === undefined) {
res.render('sendTransaction', {
txSuccess: 0,
blockHash: 'Hash Undefined'
});
res.end();;
} else {
res.render('sendTransaction', {
txSuccess: 1,
blockHash: txHash,
});
res.end();;
}
});
});
欢迎任何建议, 谢谢!
【问题讨论】:
标签: blockchain ethereum web3js parity