web3.eth.getAccounts() returns list of accounts.
Is there a way around to get the private key of one of the account from the list returned from the above code?
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.Sign up to join this community
You cannot get the private key from
web3.eth.getAccounts() directly, but there's a few workarounds to do this with ganache:
Specify a mnemonic phrase with the
-m option, e.g.
ganache-cli -m "stereo consider quality wild fat farm symptom bundle laundry side one lemon", this will derive private keys from the mnemonic phrase (with the derivation path
--account_keys_path option to save all private keys to a file, e.g.
ganache-cli --account_keys_path keys.json. This will result in a JSON file with all addresses, private keys and public keys.
--account option to manually specify a private key and balance, e.g.
ganache-cli --account "0x31c354f57fc542eba2c56699286723e94f7bd02a4891a0a7f68566c2a2df6795,1000000000000000000". This will assign 1 ETH (= 1000000000000000000 Wei) to the address corresponding to this private key. You can use the
--account option multiple times, with different private keys.