const accountFrom = web3.eth.accounts.privateKeyToAccount(privateKey);

getting error: throw new web3_errors_1.InvalidPrivateKeyError(); ^

InvalidPrivateKeyError: Invalid Private Key, Not a valid string or uint8Array
at parseAndValidatePrivateKey

2 Answers 2


Well, obviously it doesn't like your private key format.

I'm unsure what style private keys the function accepts. A typical private key is, for example, afdfd9c3d2095ef696594f6cedcae59e72dcd697e2a7521b1578140422a4f890 (taken from a google result). That's in hexadecimal, so you may need to prepend it with 0x.

Basically, easiest just to try and see what format works. Or read the documentation.


privatekey=0xafdfd9c3d2095ef696594f6cedcae59e72dcd697e2a7521b1578140422a4f890 you have to add '0x' before your privatekey

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.