Search code examples
node.jskeyprivate

Error Code: -5, Invalid private key encoding for Litecoin Private Key


I am using litecore-lib in nodejs.

Code:

var pkey = new litecore.PrivateKey();
var address = pkey.toAddress();

spawn('litecoin-cli',['importprivkey',pkey]);

But it gives me Error Message:

error code: -5 error message: Invalid private key encoding

Please Help!!?

Reference: https://github.com/litecoin-project/litecore-lib/blob/master/docs/examples.md#generate-a-random-address


Solution

  • var pkey = new litecore.PrivateKey();
    var address = pkey.toAddress();
    
    spawn('litecoin-cli',['importprivkey',pkey.toWIP()]);
    

    Forgot to convert the address to WIP format. Now working fine