How to Create Ethereum Accounts with Geth
In this video we'll install geth, create a local network, and create our first Ethereum account.
Get the project source code below, and follow along with the lesson material.
Download Project Source CodeTo set up the project on your local machine, please follow the directions provided in the README.md
file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.
In this video we'll install geth, create a local network, and create our first Ethereum account.
You can get genesis.json
here
To download geth head on over to the download page and download the binary for your system.
When you unzip it, you should have a binary named geth
, which you need to save somewhere:
mkdir -p ~/courses/newline-web3
cd ~/courses/newline-web3
mkdir bin
cp geth ./bin/geth
Now that we have geth
, we need to do some initial configuration.
For our private node we are not joining the production Ethereum network. We're not going to download the history of everything that has happened in Ethereum thus far. Instead, we're going to start our own private network. We're going to start with a clean slate.
This clean slate means that we are creating our own blockchain. I know that we haven't talked about what a blockchain is or how it works, but we will. For now, just think of it like your test database and your production database -- you can't just merge your test database into your production database and expect it to work.
Similarly, changes to our local Ethereum blockchain will have no effect on the production Ethereum network.
We're going to configure our local test blockchain by using this configuration file, genesis.json
. You can get a copy of this file from the lesson notes.
Each of these configuration parameters will make sense in time, but for now, just copy this file and save it as genesis.json
.
When we boot geth
it is going to save it's "database" in a folder on our disk. This folder saves the state of our blockchain, and more importantly, the keys to our accounts. We will specify this folder every time we boot our geth
node.
Let's initialize our node now:
./bin/geth --datadir=./datadir init genesis.json
ls
tree datadir
We can see that datadir
was created for us and it contains two folders: geth
and keystore
. The geth
directory holds our blockchain data. The keystore
directory, will hold our accounts keys, once we have them.
geth
contains a number of commands and options. We can see the list by running --help
./bin/geth --help | more
One of the first things we're going to need are accounts. We can create an account like so:
./bin/geth --datadir=./datadir account new
# abc123
We're going to need this password later, so I'm just going use the password abc123
. Obviously, you need to use a strong password when you start handling real funds.
Notice that when we created this account, it output an address, which is this long string of characters. This is your receiving address -- it's okay for it to be shared publicly.
We can now see it in our list of accounts, by calling account list
:
./bin/geth --datadir=./datadir account list
And now if we look at datadir:
tree datadir
You can see that we have a new file in keystore.
cat datadir/keystore/UTC--2017-07-24T17-24-51.466085765Z--a91aaf38a9020d893e2f94e42f8060b7ee70026c
# I'm going to pipe it through jq for readability
cat datadir/keystore/UTC--2017-07-24T17-24-51.466085765Z--a91aaf38a9020d893e2f94e42f8060b7ee70026c | jq '.'
Here is our "address" and a variety of other parameters. While the address can be publicly shared, the rest of it needs to remain secret. If someone had the information in this file, they would be able to steal all Ethereum controlled by this account.
There's another important and interesting thing you should know about accounts: they're generated completely offline.
When you create an account with Facebook, you'll hit Facebook's servers and they'll create an account in their database which you can use. When you create a traditional bank account, you go to your bank, prove your identity, ask them to create an account for you, and they create an account in their database and they let you use it.
Ethereum accounts (and Bitcoin, too) are generated from an algorithm, completely offline. You're not hitting a remote server to generate this address. In fact, no one knows that this address even exists until it's part of a transaction in the network.
In one sense, you're just picking an address at random out of a huge pool of possible addresses.
If you're familiar with SSH, it's a lot like generating SSH-keys -- you don't ask for permission from a central server to generate SSH keys -- you generate it from randomness and an algorithm on your computer.
So generate as many addresses as you need -- just make sure you securely backup your private keys.
Lesson Transcript
[00:00 - 00:11] To download Geth, head on over to the download page and download the binary for your system. When you unzip it, you should have a binary named Geth which you need to save somewhere.
[00:12 - 00:27] So I'm going to make a new directory, courses, new line, web 3, and I'm going to make a bin directory and copy Geth into it. Now that we have Geth, we need to do some initial configuration.
[00:28 - 00:36] For our private node, we are not joining the production Ethereum network. We're not going to download the history of everything that has happened in the Ethereum network this far.
[00:37 - 00:42] Instead, we're going to start our own private network. We're going to start with a clean slate.
[00:43 - 00:50] This clean slate means that we are creating our own blockchain. I know that we haven't talked about what a blockchain is or how it works, but we will.
[00:51 - 00:58] For now, just think of it like your test database and your production database. You can't just merge your test database into your production database and expect it to work.
[00:59 - 01:09] Similarly, changes to our local Ethereum blockchain will have no effect on the production Ethereum network. We're going to configure our local test blockchain by using this configuration file, Genesis.json.
[01:10 - 01:19] You can get a copy of this file from the lesson notes. Each of these configuration parameters will make sense in time, but for now, just copy this file and save it as Genesis.json.
[01:20 - 01:32] When we boot Geth, it's going to save its database in a folder on our disk. This folder saves the state of our blockchain and, more importantly, the keys to our accounts.
[01:33 - 01:37] We will specify this folder every time we boot our Geth node. Let's initialize our node now.
[01:38 - 01:52] I'm going to type ./bin/geth-dur=data-dur, in it and pass the Genesis.json. So I can LSS this folder and look what's inside DataDur.
[01:53 - 02:02] We can see that DataDur was created for us and it contains two folders, Geth and KeyStore. The Geth directory holds our blockchain data.
[02:03 - 02:08] The KeyStore directory will hold our account keys once we have them. Geth contains a number of commands and options.
[02:09 - 02:15] We can see the list by running --help. One of the first things we're going to need are accounts.
[02:16 - 02:25] We can create an account like so. /bin/geth-dur=data-dur, account new.
[02:26 - 02:34] We're going to need this password later, so I'm just going to use the password "abc123". Obviously, you need to use a strong password when you start handling real funds .
[02:35 - 02:43] Notice that when we created this account, it output an address, which is a long string of characters. This is your receiving address and it's okay for it to be shared publicly.
[02:44 - 02:52] We can now see that address in our list of accounts by calling "accountsList". Now if we look at the DataDur, you can see that we have a new file in the Key Store.
[02:53 - 03:04] We can cut that file out. But that's not very clear to look at, so I'm going to pipe it through a tool "j q" for readability.
[03:05 - 03:13] Here's our address in a variety of other parameters. While the address can be publicly shared, the rest of it needs to remain secret .
[03:14 - 03:22] If someone had the information in this file, they would be able to steal all of the Ethereum controlled by this account. There's another important and interesting thing that you should know about accounts.
[03:23 - 03:31] They're generated completely offline. For comparison, when you create an account with Facebook, you hit Facebook's servers and they'll create an account in their database which you can use.
[03:32 - 03:42] And similarly, when you create a traditional bank account, you go to your bank, you prove your identity, and you ask them to create an account for you. They create an account in their database and they let you use it.
[03:43 - 03:51] Ethereum accounts, and Bitcoin too, are generated from an algorithm, completely offline. You're not hitting a remote server to generate this address.
[03:52 - 04:02] In fact, no one knows that this address even exists until it's part of a transaction in the network. In one sense, you're just picking an address at random out of a huge pool of possible addresses.
[04:03 - 04:10] If you're familiar with SSH, it's a lot like generating SSH keys. You don't ask for permission from a central server to generate an SSH key.
[04:11 - 04:17] You generate it from randomness and an algorithm on your computer. So you can generate as many addresses as you need.
[04:18 - 04:20] Just make sure that you securely backup your private keys.
[00:00 - 00:11] To download Geth, head on over to the download page and download the binary for your system. When you unzip it, you should have a binary named Geth which you need to save somewhere.
[00:12 - 00:27] So I'm going to make a new directory, courses, new line, web 3, and I'm going to make a bin directory and copy Geth into it. Now that we have Geth, we need to do some initial configuration.
[00:28 - 00:36] For our private node, we are not joining the production Ethereum network. We're not going to download the history of everything that has happened in the Ethereum network this far.
[00:37 - 00:42] Instead, we're going to start our own private network. We're going to start with a clean slate.
[00:43 - 00:50] This clean slate means that we are creating our own blockchain. I know that we haven't talked about what a blockchain is or how it works, but we will.
[00:51 - 00:58] For now, just think of it like your test database and your production database. You can't just merge your test database into your production database and expect it to work.
[00:59 - 01:09] Similarly, changes to our local Ethereum blockchain will have no effect on the production Ethereum network. We're going to configure our local test blockchain by using this configuration file, Genesis.json.
[01:10 - 01:19] You can get a copy of this file from the lesson notes. Each of these configuration parameters will make sense in time, but for now, just copy this file and save it as Genesis.json.
[01:20 - 01:32] When we boot Geth, it's going to save its database in a folder on our disk. This folder saves the state of our blockchain and, more importantly, the keys to our accounts.
[01:33 - 01:37] We will specify this folder every time we boot our Geth node. Let's initialize our node now.
[01:38 - 01:52] I'm going to type ./bin/geth-dur=data-dur, in it and pass the Genesis.json. So I can LSS this folder and look what's inside DataDur.
[01:53 - 02:02] We can see that DataDur was created for us and it contains two folders, Geth and KeyStore. The Geth directory holds our blockchain data.
[02:03 - 02:08] The KeyStore directory will hold our account keys once we have them. Geth contains a number of commands and options.
[02:09 - 02:15] We can see the list by running --help. One of the first things we're going to need are accounts.
[02:16 - 02:25] We can create an account like so. /bin/geth-dur=data-dur, account new.
[02:26 - 02:34] We're going to need this password later, so I'm just going to use the password "abc123". Obviously, you need to use a strong password when you start handling real funds .
[02:35 - 02:43] Notice that when we created this account, it output an address, which is a long string of characters. This is your receiving address and it's okay for it to be shared publicly.
[02:44 - 02:52] We can now see that address in our list of accounts by calling "accountsList". Now if we look at the DataDur, you can see that we have a new file in the Key Store.
[02:53 - 03:04] We can cut that file out. But that's not very clear to look at, so I'm going to pipe it through a tool "j q" for readability.
[03:05 - 03:13] Here's our address in a variety of other parameters. While the address can be publicly shared, the rest of it needs to remain secret .
[03:14 - 03:22] If someone had the information in this file, they would be able to steal all of the Ethereum controlled by this account. There's another important and interesting thing that you should know about accounts.
[03:23 - 03:31] They're generated completely offline. For comparison, when you create an account with Facebook, you hit Facebook's servers and they'll create an account in their database which you can use.
[03:32 - 03:42] And similarly, when you create a traditional bank account, you go to your bank, you prove your identity, and you ask them to create an account for you. They create an account in their database and they let you use it.
[03:43 - 03:51] Ethereum accounts, and Bitcoin too, are generated from an algorithm, completely offline. You're not hitting a remote server to generate this address.
[03:52 - 04:02] In fact, no one knows that this address even exists until it's part of a transaction in the network. In one sense, you're just picking an address at random out of a huge pool of possible addresses.
[04:03 - 04:10] If you're familiar with SSH, it's a lot like generating SSH keys. You don't ask for permission from a central server to generate an SSH key.
[04:11 - 04:17] You generate it from randomness and an algorithm on your computer. So you can generate as many addresses as you need.
[04:18 - 04:20] Just make sure that you securely backup your private keys.