import * as fs from "fs";
import * as bip39 from "bip39";
import { ethers } from "ethers";

// Ethers
(async (): Promise<void> => {
  const numWallets = 3;
  const wallets: string[] = [];
  const privateKeys: string[] = [];
  const addresses: string[] = [];

  console.log("Generating wallets...");

  for (let i = 0; i < numWallets; i++) {
    const mnemonic = bip39.generateMnemonic(256); // 256 bits of entropy for 24 words
    const wallet = ethers.Wallet.fromMnemonic(mnemonic);
    wallets.push(mnemonic);
    privateKeys.push(wallet.privateKey);
    addresses.push(wallet.address);
  }

  console.log("Saving result locally...");

  fs.writeFileSync("dist/seed-phrases.txt", wallets.join("\n"));
  fs.writeFileSync("dist/public-keys.txt", addresses.join("\n"));
  fs.writeFileSync("dist/private-keys.txt", privateKeys.join("\n"));

  console.log(
    `Successfully generated and saved ${numWallets} wallets. You can view your wallets in the dist folder`
  );
})();


// Web3
// const web3 = new Web3();

// (async (): Promise<void> => {
//   const numWallets = 3;
//   const seeds = [];
//   const privateKeys = [];
//   const addresses = [];

//   console.log("Generating wallets...");

//   for (let i = 0; i < numWallets; i++) {
//     let account = web3.eth.accounts.create();
//     let seed = bip39.entropyToMnemonic(account.privateKey.slice(2));

//     const provider = new HDWalletProvider(
//       {
//         privateKeys: [PRIVATE_KEY_1.slice(2)],
//         providerOrUrl: SdkConfig._rpcUrl,
//       },
//     );

//     web3.setProvider(<any>provider);

//     seeds.push(seed);
//     privateKeys.push(account.privateKey);
//     addresses.push(provider.getAddress());
//   }

//   console.log("Saving result locally...");

//   if (!fs.existsSync("dist")) {
//     fs.mkdirSync("dist");
//   }

//   fs.writeFileSync("dist/seed-phrases.txt", seeds.join("\n"));
//   fs.writeFileSync("dist/public-keys.txt", addresses.join("\n"));
//   fs.writeFileSync("dist/private-keys.txt", privateKeys.join("\n"));

//   console.log(
//     `Successfully generated and saved ${numWallets} wallets. You can view your wallets in the dist folder`
//   );
// }
// )();
