Created
January 2, 2017 18:46
-
-
Save bitgord/0d2682d0ed8944a65d0eb33948d05429 to your computer and use it in GitHub Desktop.
Create a private network on Ethereum using CLI / Go-Ethereum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
First look at the documentation on the Ethereum Go Github. | |
https://github.com/ethereum/go-ethereum | |
You will find a section with <code>init</code> and on "Operating a Private Network. In that section is | |
an example genesis.json file, also pasted below. You can change these parameters however you want. | |
I suggest that you make a random nonce to avoid people connecting to your private chain. The alloc | |
object is the prefund accounts with tokens. | |
{ | |
"coinbase" : "0x0000000000000000000000000000000000000000", | |
"difficulty" : "0x20000", | |
"extraData" : "", | |
"gasLimit" : "0x2fefd8", | |
"nonce" : "0x0000000000000042", | |
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000", | |
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", | |
"timestamp" : "0x00", | |
"alloc": { | |
"0x0000000000000000000000000000000000000001": { | |
"balance": "111111111" | |
}, | |
"0x0000000000000000000000000000000000000002": { | |
"balance": "222222222" | |
} | |
} | |
} | |
Once you have setup this genesis.json file you need to run it from your terminal with this command. | |
<code>geth --datadir /path/to/genesis.json init genesis.json</code> | |
The datadir section is optional, though is recommended because otherwise the private chain is | |
started in the default folder, or gets connected to the live ethereum blockchain if you are a full | |
node. When executed in your terminal, you should get back a success message in your terminal. | |
You should also have a new folder called "chaindata". | |
You can now connect to your private blockchain using geth. Geth now runs the same way it does on | |
the live blockchain but on your testnet. In the message that is returned from the terminal, it is | |
important to note the enode you are listening at and the IPC endpoint to connect other nodes. | |
<code>geth --datadir /path/to/genesis.json | |
If your terminal returns a message saying server started, you have successfully connected to your | |
private chain. You should now have 3 more folders created in your private chain directory including | |
dapp, nodekey and nodes. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment