Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: derive wallets from HD wallet using address_index #167

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions 15_MultiTransfer/MultiTransfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ console.log("\n2. 通过HD钱包派生20个钱包")
const numWallet = 20
// 派生路径:m / purpose' / coin_type' / account' / change / address_index
// 我们只需要切换最后一位address_index,就可以从hdNode派生出新钱包
let basePath = "m/44'/60'/0'/0";
let addresses = [];
for (let i = 0; i < numWallet; i++) {
let hdNodeNew = hdNode.derivePath(basePath + "/" + i);
let hdNodeNew = hdNode.derivePath(i.toString());
let walletNew = new ethers.Wallet(hdNodeNew.privateKey);
addresses.push(walletNew.address);
}
Expand Down
3 changes: 1 addition & 2 deletions 15_MultiTransfer/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ tags:
const numWallet = 20
// 派生路径:m / purpose' / coin_type' / account' / change / address_index
// 我们只需要切换最后一位address_index,就可以从hdNode派生出新钱包
let basePath = "m/44'/60'/0'/0";
let addresses = [];
for (let i = 0; i < numWallet; i++) {
let hdNodeNew = hdNode.derivePath(basePath + "/" + i);
let hdNodeNew = hdNode.derivePath(i.toString());
let walletNew = new ethers.Wallet(hdNodeNew.privateKey);
addresses.push(walletNew.address);
}
Expand Down
3 changes: 1 addition & 2 deletions 16_MultiCollect/MultiCollect.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ console.log("\n2. 通过HD钱包派生20个钱包")
const numWallet = 20
// 派生路径:m / purpose' / coin_type' / account' / change / address_index
// 我们只需要切换最后一位address_index,就可以从hdNode派生出新钱包
let basePath = "m/44'/60'/0'/0";
let wallets = [];
for (let i = 0; i < numWallet; i++) {
let hdNodeNew = hdNode.derivePath(basePath + "/" + i);
let hdNodeNew = hdNode.derivePath(i.toString());
let walletNew = new ethers.Wallet(hdNodeNew.privateKey);
wallets.push(walletNew);
console.log(walletNew.address)
Expand Down
3 changes: 1 addition & 2 deletions 16_MultiCollect/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ tags:
const numWallet = 20
// 派生路径:m / purpose' / coin_type' / account' / change / address_index
// 我们只需要切换最后一位address_index,就可以从hdNode派生出新钱包
let basePath = "m/44'/60'/0'/0";
let wallets = [];
for (let i = 0; i < numWallet; i++) {
let hdNodeNew = hdNode.derivePath(basePath + "/" + i);
let hdNodeNew = hdNode.derivePath(i.toString());
let walletNew = new ethers.Wallet(hdNodeNew.privateKey);
wallets.push(walletNew);
console.log(walletNew.address)
Expand Down
3 changes: 1 addition & 2 deletions en/15_MultiTransfer/MultiTransfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ console.log("\n2. Derive 20 wallet addresses from the HD wallet");
const numWallet = 20;
// Derivation path: m / purpose' / coin_type' / account' / change / address_index
// We only need to change the last part, address_index, to derive new wallets from hdNode
let basePath = "m/44'/60'/0'/0";
let addresses = [];
for (let i = 0; i < numWallet; i++) {
let hdNodeNew = hdNode.derivePath(basePath + "/" + i);
let hdNodeNew = hdNode.derivePath(i.toString());
let walletNew = new ethers.Wallet(hdNodeNew.privateKey);
addresses.push(walletNew.address);
}
Expand Down
3 changes: 1 addition & 2 deletions en/15_MultiTransfer/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ Next, we will write a script that calls the `Airdrop` contract to transfer `ETH`
const numWallet = 20;
// Derivation path: m / purpose' / coin_type' / account' / change / address_index
// We only need to change the last part, address_index, to derive new wallets from hdNode
let basePath = "m/44'/60'/0'/0";
let addresses = [];
for (let i = 0; i < numWallet; i++) {
let hdNodeNew = hdNode.derivePath(basePath + "/" + i);
let hdNodeNew = hdNode.derivePath(i.toString());
let walletNew = new ethers.Wallet(hdNodeNew.privateKey);
addresses.push(walletNew.address);
}
Expand Down
3 changes: 1 addition & 2 deletions en/16_MultiCollect/MultiCollect.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ console.log("\n2. Derive 20 wallets from HD wallet")
const numWallet = 20
// Derivation path: m / purpose' / coin_type' / account' / change / address_index
// We only need to switch the last address_index to derive new wallets from hdNode
let basePath = "m/44'/60'/0'/0";
let wallets = [];
for (let i = 0; i < numWallet; i++) {
let hdNodeNew = hdNode.derivePath(basePath + "/" + i);
let hdNodeNew = hdNode.derivePath(i.toString());
let walletNew = new ethers.Wallet(hdNodeNew.privateKey);
wallets.push(walletNew);
console.log(walletNew.address)
Expand Down
3 changes: 1 addition & 2 deletions en/16_MultiCollect/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ After interacting and playing around with the chain, we need to consolidate and
const numWallet = 20
// Derivation path: m / purpose' / coin_type' / account' / change / address_index
// We only need to switch the last address_index to derive a new wallet from hdNode
let basePath = "m/44'/60'/0'/0";
let wallets = [];
for (let i = 0; i < numWallet; i++) {
let hdNodeNew = hdNode.derivePath(basePath + "/" + i);
let hdNodeNew = hdNode.derivePath(i.toString());
let walletNew = new ethers.Wallet(hdNodeNew.privateKey);
wallets.push(walletNew);
console.log(walletNew.address)
Expand Down