Truffle default account private keys

private-keytesttruffletruffle-test

Is there a way in truffle develop tests to access the list of private keys in the same way we can access the list of accounts?

Basically, for every contract I need to test, the truffle test contract begins like :

contract("Testing Public Pool",function(accounts){....}

"accounts" is an array with the 10 default accounts generated by truffle when running the "truffle develop" command.

But is there a similar array for the private keys (that are also displayed when running the command)? I know I could copy/paste them manually but it is kind of annoying….

Best Answer

I think there are two possible solutions to this.

  1. The first is to use HDWalletProvider

https://www.npmjs.com/package/@truffle/hdwallet-provider

You can configure it in your truffle-config.js

  1. Second approach would be to use mnemonics as explained in this answer:

How to get private keys on Truffle from Ganache accounts

Related Topic