How to generate Ethereum wallet address in C#

By | 25. April 2019

With this short article we will start series of blockchain related topics. Mostly we cover questions for beginners, but eventually we will also look into more complex themes.

So today we start with simple Ethereum address/account generator.


First we create small Windows form application with button to generate address and two edit boxes to show public address and private key.


We will use Nethereum.Portable nuget package. Though this package contains much more than needed for address generation, we will us it as it will be also in future blog posts to come.

Also reference to System.Numerics must be added.

The code is few lines only.

First we generate random private key, convert it to hex string format and after that calculate public key from private key.  Private key always determines the public key.

using Nethereum.Hex.HexConvertors.Extensions;
using System;
using System.IO;
using System.Windows.Forms;

namespace CreateEthAddress
    public partial class Form1 : Form
        public Form1()

        private void buttonGenerate_Click(object sender, EventArgs e)
            var ecKey = Nethereum.Signer.EthECKey.GenerateKey();
            var privateKey = ecKey.GetPrivateKeyAsBytes().ToHex();
            var account = new Nethereum.Web3.Accounts.Account(privateKey);
            tbAddress.Text = account.Address;
            tbPrivateKey.Text = privateKey;

            using (StreamWriter sw = File.AppendText("Account.txt"))
                sw.WriteLine($"Address: {account.Address}, Private Key {privateKey}");



Found key pair is then filled to text boxes on screen but also written to text file what is created in location of executable file itself. New keys are appended to file as generated.

Keep in mind that if private key is lost then the account with all assets on it is lost too. There is no way to recover it. Also if outsider gains access to private key then he/she gains access to all assets on account.


And result is:


Source Code: (435 downloads)

Or if if you want juts for fun generate addresses then you can download binary:

Executable: (255 downloads)


Leave a Reply