const { Wallet } = require('ethers');
const wallet = Wallet.fromMnemonic('one two three four ...', `m/44'/60'/0'/0/1`);
Alternatively, you can use the
HDNode class to quickly derive child keys from a mnemonic phrase. For example:
const { utils } = require('ethers');
const hdNode = utils.HDNode.fromMnemonic('one two three four ...');
const secondAccount = hdNode.derivePath(`m/44'/60'/0'/0/1`); // This returns a new HDNode
const thirdAccount = hdNode.derivePath(`m/44'/60'/0'/0/2`);
The
HDNode can also be used to get an instance of
Wallet. This is also what
Wallet.fromMnemonic does.
const wallet = new Wallet(hdNode);