I'm running a tutorial on how to sign an ethereum transaction programmatically, and I'm getting the following error:
RangeError: private key length is invalid
This is the code:
var Web3 = require('web3');
var web3 = new Web3(new
Web3.providers.HttpProvider('https://ropsten.infura.io/'));
var util = require('ethereumjs-util');
var tx = require('ethereumjs-tx');
var privateKey = '0x...';
var publicKey = util.bufferToHex(util.privateToPublic(privateKey));
The error is on the last line, that attempts to get the public key from the private key.
My private key is an alphanumeric string with a length of 64 characters. From all I can see it's the correct length.
What am I missing?