I'm running a geth node on a digitalocean droplet with:

geth --light --rpc --rpcaddr "" --rpcapi personal,web3,net,eth --rpccorsdomain "*" --rpcport "8545" console

I'm trying to import a private key remotely with web3.js. Here's what I have :

var web3= new Web3(new Web3.providers.HttpProvider('http://my.node.ip:8545'));
var personal = new Personal(Personal.providers.HttpProvider('http://my.node.ip:8545'));

web3.eth.personal.importRawKey('0x3f91d8d53d7b25580cbf6b839213e20419cefb52bcdbf74c535d081c7006baba', "AssCheeks").then(console.log);

This returns: "Error: Returned error: invalid hex string"

How do I get this to work and where will it store the private key and address?

  • importing private keys remotely? your account balance is not going to last for long. You can use MyEtherWallet to create a JSON account from private key, if you need to convert private key to a wallet account. Or, you can use keythereum to create a wallet from a private key.
    – Nulik
    Jul 6, 2018 at 1:25
  • I'm not so sure these would work for me. My app will be creating the keys with the node package "ethers" and I just need to import those keys to my node so they can be watched and send transactions. If you're familiar with bitcoin, I need it to be the same as: bitcoin-cli importprivkey <private key> <account name>
    – Setheroni
    Jul 6, 2018 at 2:29
  • The ECDSA library that Ethereum uses is copied from bitcoin-core and there is no need for any "import" private key software, because private key is just a number. Just a simple number like 1,000,000 , but very big and generated according to some mathematical rules to be random enough. You don't need to import it, because its format is simple bytes. Just transfer it and you have it "imported"
    – Nulik
    Jul 6, 2018 at 13:14
  • But how do I transfer it automatically with a Node JS application? With bitcoin, I create the keys when I create an account and send them to bitcoin-core using "bitcoin-cli importprivkey". How can I accomplish this with Ethereum?
    – Setheroni
    Jul 7, 2018 at 15:37
  • Private keys are bytes. You are asking how to transfer bytes with Node JS application? You don't know how to transfer bytes over the internet?
    – Nulik
    Jul 8, 2018 at 1:49

2 Answers 2


This problem is really stupid: importRawKey is not expecting "0x" at the start of the hex string.

So if you have

privateKey = "0xffffffffffffff" // etc
pass = "blah"

Try chopping off the first 2 characters with .slice(2):

web3.eth.personal.importRawKey(privateKey.slice(2), pass)
web3.personal.importRawKey(some_private_key, 'the-passphrase')

see https://web3py.readthedocs.io/en/stable/web3.personal.html for more details

What you've got in your question as the first argument is the address, which is actually what importRawKey returns. what you need to supply is the private key, which you can get from the keystore using keythereum: see https://ethereum.stackexchange.com/a/36022/45919 for the node.js commands

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.