Replies: 5 comments 1 reply
-
I just met the same problem since I'm new to ether.js😂. It seems that the wallet.derivePath() will append the parameter as a child path to the current wallet path, you can try this and find it out: // create a HD wallet.
const wallet = ethers.Wallet.createRandom();
console.log(wallet);
// and then I want to derive path from the wallet.
const account1 = wallet.derivePath("1");
console.log(account1);
// OR just derive child
const account2 = wallet.deriveChild(1);
console.log(account2); |
Beta Was this translation helpful? Give feedback.
-
I wanted to derive a sibling path(depth 5) and find that I have to create the wallet with the path. Don't know if there is another way to derive. const phrase = 'lobster scan season burst circle fatigue guide real better good despair lock';
const mnemonic = Mnemonic.fromPhrase(phrase);
const path = `m/44'/60'/0'/0/1`;
const hdWallet = ethers.HDNodeWallet.fromMnemonic(mnemonic!, path);
console.log(hdWallet); |
Beta Was this translation helpful? Give feedback.
-
If you wish to create a new (random) Wallet at // Create a root wallet (this will have no mnemonic as a seed cannot be reversed)
const root = HDNodeWallet.fromSeed(randomBytes(16));
// Create a root wallet with a mnemonic
const root = HDNodeWallet.createRandom(null, "m");
// Derive account 1:
const account1 = w.derivePath(getAccountPath(1))
// Derive account 2:
const account2 = w.derivePath(getAccountPath(2)) The math involved on an HDNode is intentionally designed to only allow very specific derivation options (see BIP 32), but as a result has some very cool features. For example, it is possible to share a neutered public key, which allows all child addresses to be computed, without sharing the private keys. It can optionally (by using hardened vs. non-hardened keys) be used to prevent an owner of a private key from computing parent private keys. And in no instance, can the mnemonic be derived. There are lots of cool ways to use the HD algorithm. :) Here are the docs for HD Wallet, and if you want to mess around, try out the playground where you can easily experiment with the API. :) |
Beta Was this translation helpful? Give feedback.
-
(as a quick note; using a non-standard path will almost certainly ensure your wallet will not work correctly in other Wallets, like MetaMask or Ledger, which rely on following the standard paths. This is why |
Beta Was this translation helpful? Give feedback.
-
Also, moving this to discussions. :) |
Beta Was this translation helpful? Give feedback.
-
Ethers Version
6.13.2
Search Terms
wallet, depth
Describe the Problem
Expected: I can use
createRandom
function, that must be created HD wallet with depth zero.Actual: But, that was HD wallet with depth five.
So, HD wallet with depth five couldn't make child addresses using
derivePath
function.Is it a bug or how do I create HD wallet with depth zero?
Code Snippet
Contract ABI
No response
Errors
Environment
node.js (v12 or newer)
Environment (Other)
No response
Beta Was this translation helpful? Give feedback.
All reactions