Running parity private PoA chain, using latest parity client + nodejs + web3.js 1.0
When I try to sign a transaction and then send it following web3.js 1.0 documentation (sendTransaction and sendSignedTransaction) I get the following error:
Unhandled rejection Error: Returned error: Invalid RLP. at Object.ErrorResponse (/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) at XMLHttpRequest._setReadyState (/home/simoh/node_modules/xhr2/lib/xhr2.js:354:12) at 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 (internal/process/next_tick.js:138:11) at process._tickCallback (internal/process/next_tick.js:180:9)
This is my code:
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);
})
The account is defined in the following way:
var account = web3.eth.accounts.privateKeyToAccount(privateKey);
I cannot figure out what I am doing wrong.
In addition it is not very clear to me why as example for sendSignedTransaction, it is shown a method that uses 'ethereumjs-tx' which is different than the one proposed in the documentation. Using this second method with 'ethereumjs-tx' the same transaction as the code above is succesfully signed and sent.
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);
Also when I use web3.eth.accounts.recoverTransaction(result.rawTransaction)
it is showing different public key than what's expected...