[Tutorial] Make your own Ethereum Address From Scratch

Get a wallet, the mathematical way:

Requirements:

  • Install Geth (for verification)
  • Install keccak256, depends on your system. Check this. If you are having a hard time you can use this online generator.

Some amazing mathematics underlies a lot of the special abilities that are now possible to do with the world of Web3. Although you don’t need to understand it to be able to use it, the reason I am including this here is that it’s imperative to intuit how it all works without central servers managing the addresses. And because learning is awesome!

For ethereum, you are using the features of beautiful graph:

to generate a public/private key pair. A keypair allows you to share secret messages with people online and also to prove that you intended to sign digital files. This lies at the heart of decentralized tech and we want to be sure that you don’t miss out on understanding it. Ethereum’s addresses are derived by taking a hash of the public key. A hash is a function that creates a unique fixed length string from various inputs.

To generate your own ethereum address by generating your own public/private key pair and hashing your public key, you can follow this tutorial and find the code here.

Important note, I made a mistake saying that keccak is related to the elliptic curve cryptography during our call today. It’s not, it’s actually based on sponge functions.

If you’re looking for step by step code you can cut/paste into your terminal, check this out:

# Generate the private and public keys
openssl ecparam -name secp256k1 -genkey -noout |   openssl ec -text -noout > Key

# Extract the public key and remove the EC prefix 0x04
cat Key | grep pub -A 5 | tail -n +2 |  tr -d '\n[:space:]:' | sed 's/^04//' > pub

# Extract the private key and remove the leading zero byte
cat Key | grep priv -A 3 | tail -n +2 | tr -d '\n[:space:]:' | sed 's/^00//' > priv

# Generate the hash and take the address part
cat pub | keccak-256sum -x -l | tr -d ' -' | tail -c 41 > address

# (Optional) import the private key to geth
geth account import priv

If you’d like to nerd out a little more on how you can create a one way function from the elliptic curve above, read this amazing break down. It is also where I shared the step by step RSA example.

3 Likes

Thanks for the detailed instructions, I tried to download Geth using the link and it didn’t work.

So I am using this link: https://geth.ethereum.org/downloads/

Commands to generate public/private key
$ openssl ecparam -name secp256k1 -genkey -noout
$ openssl ecparam -name secp256k1 -genkey -noout | openssl ec -text -noout
$ openssl ecparam -name secp256k1 -genkey -noout | openssl ec -text -noout > Key
$ cat Key | grep pub -A 5 | tail -n +2 | tr -d ‘\n[:space:]:’ | sed ‘s/^7-04//’ > pub
$ cat Key | grep priv -A 3 | tail -n +2 | tr -d ‘\n[:space:]:’ | sed ‘s/^3-00//’ > priv
$ cat pub | keccak-256sum -x -l | tr -d ’ -’ | tail -c 41 > address
HELP: keccak-256sum: file is malformated

3 Likes

I already happened to have geth…but had trouble with https://github.com/ethereum/eth-hash (keccak-256sum) install, so I found https://github.com/maandree/sha3sum, cloned the repo, ran make, and then I had access to keccak-256sum binary!

After that, I got it to work.

3 Likes

when i am trying to install linkeccak then it’s giving me below error cna you please tell how you sort out this issue. and i am installing it on Mac os Mojave.

cc -shared -Wl,-soname,libkeccak.so.1 -o libkeccak.so digest.o libkeccak_behex_lower.o libkeccak_behex_upper.o libkeccak_degeneralise_spec.o libkeccak_generalised_sum_fd.o libkeccak_hmac_copy.o libkeccak_hmac_digest.o libkeccak_hmac_fast_digest.o libkeccak_hmac_fast_update.o libkeccak_hmac_set_key.o libkeccak_hmac_unmarshal.o libkeccak_hmac_update.o libkeccak_hmac_wipe.o libkeccak_state_copy.o libkeccak_state_initialise.o libkeccak_state_marshal.o libkeccak_state_unmarshal.o libkeccak_state_wipe.o libkeccak_state_wipe_message.o libkeccak_state_wipe_sponge.o libkeccak_unhex.o -s
ld: warning: option -s is obsolete and being ignored
ld: unknown option: -soname
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [libkeccak.so] Error 1

1 Like

Thank you Bilal for heads up. First I tried doing it on my own but finally I had to take your help. I did it on a Windows machine (You can call me a rookie). So now if anyone needs help generating wallet on a Windows machine, feel free to ping me.

2 Likes

Just if anyone ended up to this post, you can download geth from here for different OS

It’s stuck at linking keccak’s object files and getting out the executable. You can use the online generator instead for now :wink: … and ahh! please share with us the source where you tried to install keccak manually

I have installed keccak manually, if I recall correctly I got it from here: https://github.com/maandree/sha3sum

Are people still having issues with keccak?

Very interesting, can you check the values of the Key and pub / priv files? Are they actually getting created?

Yeah i cloned that library when i try to install then its giving the linkeccak library issue. But i i try to install linkeccak library it gives me lot of error. Earlier i mentioned the errors above in the topic.

Hi Tintin, I am using windows 10 unsuccessfully. I would appreciate if you give me a hand crating address and keys under this OS.
Best regards

I’m on Linux (Ubuntu 18.04) and these steps have worked for me :

  1. git clone https://github.com/maandree/libkeccak
  2. cd libkeccak
  3. make
  4. sudo make install

If the installation is ok then do these steps :

  1. git clone https://github.com/maandree/sha3sum
  2. cd sha3sum
  3. make

Best regards

1 Like

Maybe something useful, use sudo make install PREFIX=/usr (for the step 4 of libkeccak installation) to avoid shared library errors when you want to use sha3sum.

1 Like

Hey Albnar! Following are the steps:

  1. Install openssl from here
  2. Install geth from https://geth.ethereum.org/downloads/
  3. Generate key pair using “openssl ecparam -name secp256k1 -genkey -noout | openssl ec -text -noout > Key”. The result will look like this:

Private-Key: (256 bit)
priv:
20:80:65:a2:47:ed:be:5d:f4:d8:6f:bd:c0:17:13:
03:f2:3a:76:96:1b:e9:f6:01:38:50:dd:2b:dc:75:
9b:bb
pub:
04:83:6b:35:a0:26:74:3e:82:3a:90:a0:ee:3b:91:
bf:61:5c:6a:75:7e:2b:60:b9:e1:dc:18:26:fd:0d:
d1:61:06:f7:bc:1e:81:79:f6:65:01:5f:43:c6:c8:
1f:39:06:2f:c2:08:6e:d8:49:62:5c:06:e0:46:97:
69:8b:21:85:5e
ASN1 OID: secp256k1

  1. Use “type Key” to check your keys
  2. Copy your public key and paste it in notepad. Remove all the spaces, colons ( : ) and newline characters. Also remove the 04 in the beginning of the string. Your key should look like this:

836b35a026743e823a90a0ee3b91bf615c6a757e2b60b9e1dc1826fd0dd16106f7bc1e8179f665015f43c6c81f39062fc2086ed849625c06e04697698b21855e
Save the file as ‘pub’.

  1. I used this calculator to generate keccak256 hash. Please refer image for the settings.

  2. Repeat step 5 for your private key. There is one difference; remove the leading ‘00’ if there is and save the file as ‘priv’

  3. Create Ethereum account using “geth account import priv” command. After entering the password, an address will be generated. Compare it with the last 40 characters of your keccak256 hash. If they are same, everything worked fine else repeat the process.

I followed the tutorial suggested by Bilal with a few tweaks. I hope it works for you. All the best.

2 Likes

Hi Nitin,

thank you very much for your help.

Everything run well but the last step. The generated Address from geth is totally different as the Keccak256 hash. I repeated the procedure tree times with the same results. I followed your instruction regarding the calculator settings. I used Notepad++ for edition. Public Key is 128char long and Privat 64Char long.

The only difference is the version of both programs. I installed openssl_win64 and geth for 64bit too. Should I install 32bit versions instead?

Many thanks in advance

Hi Nitin,
I am terribly sorry. I am a fool. I compared the first 40 char not the last ones :flushed:
best regards

1 Like

Don’t be so tough on yourself bro. Let’s get back to work and finish the last part of assignment. I am still clueless about where to start. May be you can help me with that.

Awesome work you guys! This aha moment of finding the last 40 vs the first 40 chars is a strong learning moment, you wont forget it and also now you know where the addresses come from.
Any idea why the random chopping of bytes?
+BG

This is awesome and should be it’s own post in the https://community.elk.cc/c/bc-iot-bootcamp/bc-week-1-theory-background subcategory :)!

Hi tintin,
I shared my public key, as indicated by Bilal.
1a93a17d51824a11bf7f0b93467f9fdbf4dff52df4f8c46f656e15127d52e1e43f00b743a36043b5b418e4d46dfb95921e0531b1f8b43c5d7d19fdb5557fe805
Now I will try to send a message. If I succeed I will share it with you. Is it OK.