0

I would like to add the keys and unlock some additional addresses at runtime for my truffle tests.

Why? I have the need to create address from a seed generated elsewhere in my test so the private keys don't exist until part of the test has run.

I'm hoping to do something like this:

EthereumBip44 = require('ethereum-bip44')
# create the hd wallet
wallet = EthereumBip44.fromPrivateSeed(tree.keccak);
confirms = [
  wallet.getAddress(0)
  wallet.getAddress(1)
  wallet.getAddress(2)
  wallet.getAddress(3)
  wallet.getAddress(4)
]

And then later I'll need to send some transactions from these accounts. How can I add them so that I can call one of my truffle functions from them?

contractCompiledWithTruffle.myFunction('dosomething', from: confirms[1])
  • An easy solution is to add an extra account at the beginning that will not be used ethereum.stackexchange.com/questions/6906/…, and when you need the new accounts just make a transfer from the extra account to them. – Ismael Jan 23 '18 at 3:15
  • The issue is that I don’t know the address I want until after the test has run because the private key is based on a result in my test. I can transfer funds, but how do I unlock to do new transactions later in my test. – Austin Fatheree Jan 24 '18 at 11:06
  • With ganache you can specify the extra account to be unlocked, then sending a transfer to the new addresses will just work. – Ismael Jan 24 '18 at 14:08
  • Do you have a ref to the documentation on this? If so you will be my hero. – Austin Fatheree Jan 25 '18 at 15:24
  • Take a look at ganache-cli documentation. It has parameter --account to create an account with a predefined private key and the parameter --unlock to unlock an account. – Ismael Jan 25 '18 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.