I can't find a way to retrieve the private key / public key / public address for a web3 account loaded via a provider. I have tried the web3.eth.accounts
command but I am not getting the private key / public key / public address .
const web3 = new Web3(provider);
web3.eth.accounts
In more details, I would like to have a HD wallet for receiving ethers on different public keys (and later selling them)
Following the advice in the doc, I am using truffle/hdwallet-provider
for the HD wallet. So now I am trying to retrieve the private key, the public key and possibly the public address via web3js for the provider created via truffle/hdwallet-provider wallet
This is my code which I run several time each time in a new node console in a cmd
.
Before starting the node console, I start a cmd
with geth --rpc --rpcport 8545
while internet is turned off so that I don't have to download/sync the blockchain
const mnemonicPhrase = 'some words ... '
const HDWalletProvider = require("@truffle/hdwallet-provider");
Web3 = require('web3');
provider = new HDWalletProvider({
mnemonic: mnemonicPhrase,
providerOrUrl: "http://localhost:8545",
numberOfAddresses: 1,
shareNonce: true,
derivationPath: "m/44'/0'/0'/0/"
});
const web3 = new Web3(provider);
web3.eth.accounts
There should be a way to retrieve the private/public key via web3.eth.accounts but I am only getting a single address
Thanks a lof for your help!
- Operating System: windows
- Ethereum client:
- Truffle version (
truffle version
): @truffle/[email protected] ([email protected]) - node version (
node --version
): v14.16.1 - npm version (
npm --version
): 6.14.12