I'm trying to sign and push a transaction using ethereumjs
and Infura
. It seems to be working and I'm getting a transaction hash back, but the transaction is not visible on Etherscan, and when I'm trying to push the hash through a service like this I get an error:
Error! Unable to broadcast Tx : {"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid RLP.","data":"RlpExpectedToBeList"},"id":1}
This is the code I'm using:
var Web3 = require('web3');
var web3 = new Web3(new
Web3.providers.HttpProvider('https://ropsten.infura.io/v3/my_api_key'));
var util = require('ethereumjs-util');
var tx = require('ethereumjs-tx');
var rawTx = {
nonce: web3.toHex(1),
gasPrice: web3.toHex(20000000000),
gasLimit: web3.toHex(30000000000),
to:...
value: web3.toHex(1000000),
data: '0xc0de',
networkId: 3
};
var privateKey = '0x...';
var p = new Buffer.from(privateKey.substring(2), 'hex');
var transaction = new tx(rawTx);
transaction.sign(p);
console.log("tx hash = " + util.bufferToHex(transaction.hash(true)));
What am I missing?