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

Example: Hardhat Private keys from mnemonic "test test test test test test test test test test test junk" #37

Open
juanfranblanco opened this issue Mar 8, 2021 · 0 comments

Comments

@juanfranblanco
Copy link
Member

juanfranblanco commented Mar 8, 2021

using System;
using System.Numerics;
using Nethereum.Web3;
using Nethereum.Web3.Accounts;
using Nethereum.Util;
using Nethereum.Hex.HexConvertors.Extensions;
using Nethereum.HdWallet;
using System.Threading.Tasks;
using NBitcoin;

public class Program
{
    private static async Task Main(string[] args)
    {
        // This samples shows how to derive or create accounts from a given word list seed in an hd wallet 

        // This uses Hardhat default mnemonic https://hardhat.org/hardhat-network/
        // 
        //Nethereum uses internally NBitcoin to derive the private and public keys, for more information on bip32 please check
        //https://programmingblockchain.gitbook.io/programmingblockchain/key_generation/bip_32

        //Initiating a HD Wallet requires a list of words and an optional password to add further entropy (randomness)

      	var words = "test test test test test test test test test test test junk";
        //Note: do not confuse the password with your Metamask password, Metamask password is used to secure the storage
        var password = "";
        var wallet = new Wallet(words, password);

        //Accounts are derived using indexes so the account at 0 will have always the same private key and address.
        for (var i = 0; i < 20; i++)
        {
            var account = wallet.GetAccount(i);
            Console.WriteLine("Account index : " + i + " - Address : " + account.Address + " - Private key : " +
                              account.PrivateKey);
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant