Ejecución de la cadena PoA privada de paridad, utilizando el cliente de paridad más reciente + nodejs + web3.js 1.0
Cuando intento firmar una transacción y luego enviarla siguiendo la documentación de web3.js 1.0 ( sendTransaction y sendSignedTransaction ), aparece el siguiente error:
Error de rechazo no manejado: Error devuelto: RLP no válido. en Object.ErrorResponse (/home/simoh/node_modules/web3-core-helpers/src/errors.js:29:16) en /home/simoh/node_modules/web3-core-requestmanager/src/index.js:137: 36 en XMLHttpRequest.request.onreadystatechange (/home/simoh/node_modules/web3-providers-http/src/index.js:64:13) en XMLHttpRequestEventTarget.dispatchEvent (/home/simoh/node_modules/xhr2/lib/xhr2.js :64:18) en XMLHttpRequest._setReadyState (/home/simoh/node_modules/xhr2/lib/xhr2.js:354:12) en XMLHttpRequest._onHttpResponseEnd (/home/simoh/node_modules/xhr2/lib/xhr2.js:509 :12) en IncomingMessage. (/home/simoh/node_modules/xhr2/lib/xhr2.js:469:24) en emitNone (events.js:110:20) en IncomingMessage.emit (events.js:207:7) en endReadableNT (_stream_readable.js :1059:12) en _combinedTickCallback (internal/process/next_tick.js:138:11) en el proceso.
Este es mi código:
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);
})
La cuenta se define de la siguiente manera:
var account = web3.eth.accounts.privateKeyToAccount(privateKey);
No puedo entender lo que estoy haciendo mal.
Además, no me queda muy claro por qué como ejemplo para sendSignedTransaction , se muestra un método que usa 'ethereumjs-tx' que es diferente al propuesto en la documentación. Usando este segundo método con 'ethereumjs-tx', la misma transacción que el código anterior se firma y envía con éxito.
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);
Además, cuando lo uso web3.eth.accounts.recoverTransaction(result.rawTransaction)
, muestra una clave pública diferente a la esperada ...
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);
}
});
nadison