1

I know I should be able to get it, but does anyone know how to get the private keys associated with the web3.eth.accounts from the testrpc?

Much thanks and upvotes to the wise sage with the answer.

2 Answers 2

1

The easiest way to find out accounts' private keys is simply just scroll up to the top in terminal. You will see something like this (obviously with different addresses and private keys)enter image description here:

4
  • Thanks for the help. This is what I was found originally, but do you know if there's any way to get them not via the old cut and paste method?
    – thefett
    Commented Oct 10, 2017 at 11:44
  • I'm not aware if such solution exists at all. Generally you don't even need private keys since accounts in testrpc are unlocked by defeault! What is your use case scenario, when you would need them? Commented Oct 10, 2017 at 12:04
  • I'm just testing out sending raw transactions (creating them and then signing them with my private key). I just wanted to see if there was an easy way to do this on the testrpc. I think I can start it up and create a bunch of the accounts with hardcoded private keys and that might be my best option
    – thefett
    Commented Oct 10, 2017 at 13:46
  • This one just came to my mind today: what if you fire up testrpc like this: testrpc --deterministic This will always create the same accounts for you (meaning every time you type testrpc --deterministic you will have the very same public addresses and private keys).You could also just use these accounts as hardcoded ones.... Commented Dec 14, 2017 at 15:22
1

i am fairly certain the web3 rpc protocol doesn't allow you pass private keys around, however here are a few workarounds:

  1. check the console output of testrpc, they are listed there.

  2. if you use a fixed seed testrpc -s <some-seed-value> you will always get the same test accounts (so you could copy the private keys to your test code/etc)

  3. you can pass in private keys you've generated.

    testrpc --account="<privatekey>,balance"

  4. you can start testrpc with accounts unlocked, which might suit what you are doing better, eg if you want to send transactions.

    testrpc --secure -u 0 -u 1

more at (https://github.com/ethereumjs/testrpc)

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.