为什么交易被标记为无效?

时间:2019-10-24 23:15:44

标签: blockchain ethereum web3js parity

我正在尝试通过从一个帐户向另一帐户发送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,向txObject等添加“ from”键/值对,等等。我还从--no-persistent-txqueue开始了奇偶校验节点,以便它不会缓存太多的事务,如建议{ {3}}。但这也没有任何改变。因此,我仍然遇到相同的错误,并且交易未通过。是什么导致此问题,我该如何解决?

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

任何建议都值得欢迎, 谢谢!

1 个答案:

答案 0 :(得分:0)

代码看起来不错,所以它必须很小,您非常接近!