By default, geth will connect to the main consensus network and begin downloading the full blockchain (very large!). To avoid this default behavior, and to instead create and mine your own private chain, you must create a custom “genesis” block (example here, and here). Here are some quick steps I used:
Use the following command to initialize your genesis file, where the file path represents the location of your genesis file (Windows):
geth --datadir "C:\Users\Ryan\Desktop\DevChain" init genesis.json
Next, we want to actually run your geth to start up your node. We could simply run the geth command, but for reasons which will be explained later, let’s run it with some additional flags. Be sure to swap out the etherbase account with your personal account so that the Ether will be pre-mined to an account you control (if you haven’t already created an account, check out the section on that).
geth --networkid=12345 --datadir "C:\Users\Ryan\Desktop\DevChain" --rpccorsdomain "*" --nodiscover --port 8545 --rpc --rpcport "8545" --etherbase=0x6c790892ee90cf0b509ef5c86036468c9eb76323 console
miner.start(1)to start a miner (1 thread).
personal.listAccountsto view all local accounts
personal.newAccount()to create a new local account.
personal.unlockAccount()to unlock an account you control.
var primaryAcct = personal.listAccounts
Before you start mining, it is a good idea to create an account first. If you haven’t already done so, it’s simple. Use one of these two methods:
geth account new
Both of these methods will prompt you for a password. If you haven’t already done so, make sure to insert one of your account addresses into the genesis block file so that you can receive the genesis funds, as it is designed to deposit money into the account you’ve specified.
To begin mining, open your web3 JS console and use the command
miner.start(1). This should start mining. After a short amount of time (assuming the difficulty set in your genesis file is low) you should have mined your first test net block!
To make sure, let’s check your account balance:
The command above calls the .getBalance() method on the coinbase account (the account allocated by the genesis block). If mined successfully, you will likely see a very large number. This is because the balance, by default, is displayed in “wei” which is the lowest denomination in Ethereum. To view how many full Ether are in that account, try this command: