运行奇偶私有PoA链,使用最新的奇偶校验客户端+ nodejs +web3.js1.0
当我尝试签署一个事务,然后按照web3.js1.0文档(sendTransaction和sendSignedTransaction)发送它时,我会得到以下错误:
未处理的拒绝错误:返回的错误:无效的RLP。(/home/simoh/node_modules/web3-core-helpers/src/errors.js:29:16) at /home/simoh/node_modules/web3-core-requestmanager/src/index.js:137:36 at XMLHttpRequest.request.onreadystatechange (/home/simoh/node_modules/web3-providers-http/src/index.js:64:13) at XMLHttpRequestEventTarget.dispatchEvent (/home/simoh/node_modules/xhr2/lib/xhr2.js:64:( 18)在(/home/simoh/node_modules/xhr2/lib/xhr2.js:354:12) XMLHttpRequest._setReadyState XMLHttpRequest._onHttpResponseEnd (/home/simoh/node_modules/xhr2/lib/xhr2.js:509:12) at IncomingMessage。(/home/simoh/node_modules/xhr2/lib/xhr2.js:469:24) at emitNone (events.js:110:20) at IncomingMessage.emit (events.js:207:7) at endReadableNT (_stream_readable.js:1059:12) at _combinedTickCallback (tick.js/process/next_tick.js:138:11) at process._tickCallback (tick.js/process/next_tick.js:180:9)
这是我的密码:
web3.eth.accounts.signTransaction({
nonce: 11377,
gasPrice: '0x00',
gasLimit: '0x2DC6C0',
to: '0x00d4dc44dfbbcb7d8369ddcd261bdaad1872d652',
from: account.address,
value: '0x16345785D8A0000',
data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057'
}, account.privateKey)
.then(function(result) {
console.log("Results: ", result)
web3.eth.sendSignedTransaction(result.rawTransaction)
.on('receipt', console.log);
})帐户的定义如下:
var account = web3.eth.accounts.privateKeyToAccount(privateKey);我不知道我做错了什么。
此外,我还不太清楚为什么作为sendSignedTransaction的例子,它显示了一个使用‘ethereumjs’的方法,它与文档中提出的方法不同。使用第二个方法和‘ethereumjs’,上面的代码相同的事务将被成功地签名和发送。
var Tx = require('ethereumjs-tx');
var privateKey = new Buffer('private key', 'hex');
var rawTx = {
nonce: 11376,
gasPrice: '0x00',
gasLimit: '0x2DC6C0',
to: '0x00d4dc44dfbbcb7d8369ddcd261bdaad1872d652',
from: '0x0013a861865d784d97c57e70814b13ba94713d4e',
value: '0x16345785D8A0000',
data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057'
}
var tx = new Tx(rawTx);
tx.sign(privateKey);
var myString = "0x"
var serializedTx = (tx.serialize()).toString('hex');
myString += serializedTx
console.log(myString);
web3.eth.sendSignedTransaction(myString)
.on('receipt', console.log);另外,当我使用web3.eth.accounts.recoverTransaction(result.rawTransaction)时,它显示的公钥与预期的不同.
发布于 2018-09-04 06:26:36
let send_add = send_public_address;
let recv_add = rec_public_address;
let transfer_amount = web3.toWei(data.amount, 'ether');
let nonce = web3.toHex(web3.eth.getTransactionCount(send_public_address));
var private_key = privatekey_sender.slice(2);
let gas = web3.toHex(data.gas_limit);
let gasPrice = web3.toHex(data.gas_price);
var rawTx = {
from: send_add,
nonce: nonce,
gasLimit: gas,
gasPrice: gasPrice,
value: web3.toHex(transfer_amount),
to: recv_add,
};
var transaction = new tx(rawTx);
var txData = new Buffer(private_key, 'hex');
transaction.sign(txData);
var serializedTx = transaction.serialize().toString('hex');
web3.eth.sendRawTransaction('0x' + serializedTx, function (err, txHash) {
if (txHash) {
next(null, txHash);
}
else if (err && err.message) {
next(err.message, null);
}
else {
next('Unable to sendRawTransaction', null);
}
});https://ethereum.stackexchange.com/questions/27546
复制相似问题