Recently, blockchain has become so popular that some friends are ready to play it. They say they have been building it for a week but have not set up the environment. Ask me to help them see how to set up the environment
So I found the official address at https://github.com/ethereum/go-ethereum
Docker is officially supported
So I created the following directory
➜ block - chain PWD/Users/jackluo/Works/block - chain ➜ block - chain ls ethereum start - ethereum. ShCopy the code
The contents of start-ethereum.sh are as follows
docker stop ethereum-node
docker rm ethereum-node
docker run -d --name ethereum-node -v /Users/jackluo/Works/block-chain/ethereum:/root \
-p 8545:8545 -p 30303:30303 \
ethereum/client-go
docker exec -it ethereum-node /bin/shCopy the code
We mounted the current Ethereum directory under /root of docker
Let’s create the private chain
➜ block-chain CD Ethereum ➜ Ethereum ls Genesis. Json privatechain
We created the genesis.json file from the official documentation and wrote
{
"config": {
"chainId": 0,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"alloc" : {},
"coinbase" : "0x0000000000000000000000000000000000000000",
"difficulty" : "0x20000",
"extraData" : "",
"gasLimit" : "0x2fefd8",
"nonce" : "0x0000000000000042",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00"
}Copy the code
Parameter, see the specific file file
Next, we launch ethereum’s Docker container
➜ block-chain ./start-ethereum.sh
Error response from daemon: No such container: ethereum-node
Error response from daemon: No such container: ethereum-node
d421da09e63900d1cc9481529ab2a5868515fb821520b548f10e0bd2f3608c0c
/ #
/ #
/ # ls
bin dev etc home lib media mnt proc root run sbin srv sys tmp usr var
/ # cd /root/
~ # ls
genesis.json privatechain
~ # cd privatechain/
~/privatechain # ls
data0 genesis.json
~/privatechain # pwd
/root/privatechain
~/privatechain #Copy the code
Next, initialize it
~/privatechain # geth --datadir data0 init genesis.json INFO [03-06|05:21:40] Maximum peer count ETH=25 LES=0 total=25 INFO [03-06|05:21:40] Allocated cache and file handles database=/root/privatechain/data0/geth/chaindata cache=16 Handles the INFO = 16 [03-06 | 05:21:40] Persisted trie from memory database nodes = 0 size = 0.00 B time = 41.5 (including s gcnodes = 0 Gcsize = 0.00 B gctime = 0 s livenodes = 1 livesize = 0.00 B INFO [03-06 | 05:21:40] Successfully demonstrate the genesis of the state The database = chaindata hash = ed1fb6... 1760ca INFO [03-06|05:21:40] Allocated cache and file handles database=/root/privatechain/data0/geth/lightchaindata Cache = 16 handles = 16 INFO [03-06 | 05:21:40] Persisted trie from memory database nodes = 0 size = 0.00 B time = 10.5 (including s gcnodes = 0 Gcsize = 0.00 B gctime = 0 s livenodes = 1 livesize = 0.00 B INFO [03-06 | 05:21:40] Successfully demonstrate the genesis of the state The database = lightchaindata hash = ed1fb6... 1760caCopy the code
Next, start the private chain
~/privatechain # geth --identity "TestNode" --rpc --rpcport "8545" --datadir data0 --port "3033" --nodiscover console INFO [03-06|05:26:44] Maximum peer count ETH=25 LES=0 total=25 INFO [03-06|05:26:44] Starting peer-to-peer node The instance = Geth/TestNode/v1.8.2 - unstable - 0 b814d32 / Linux - amd64 / go1.9.4 INFO [03-06 | 05:26:44] Allocated cache and the file handles database=/root/privatechain/data0/geth/chaindata cache=768 handles=1024 INFO [03-06|05:26:44] Initialised chain configuration config="{ChainID: 1024 Homestead: 0 DAO: <nil> DAOSupport: false EIP150: <nil> EIP155: 0 EIP158: 0 Byzantium: <nil> Constantinople: <nil> Engine: unknown}" INFO [03-06|05:26:44] Disk storage enabled for ethash caches dir=/root/privatechain/data0/geth/ethash count=3 INFO [03-06|05:26:44] Disk storage enabled for ethash DAGs dir=/root/.ethash count=2 INFO [03-06|05:26:44] Initialising Ethereum protocol versions="[63 62]" network=1 INFO [03-06|05:26:44] Loaded most recent local header number=0 Hash = ed1fb6... Ca 1760 td = 1024 INFO [03-06 | 05:26:44] the Loaded most recent local full block number = 0 hash = ed1fb6... Ca 1760 td = 1024 INFO [03-06 | 05:26:44] the Loaded most recent local fast block number = 0 hash = ed1fb6... 1760ca td=1024 INFO [03-06|05:26:44] Loaded local transaction journal transactions=0 dropped=0 INFO [03-06|05:26:44] Regenerated local transaction journal transactions=0 accounts=0 INFO [03-06|05:26:44] Starting P2P networking INFO [03-06|05:26:44] RLPx listener up self="enode://3264cbba213bc88c407c55576f148d5c2b6afa5013a7c204085e01c5e4dc24a9235bd9abf86681d0d36349fa8031367c31adb534a4 69f4ea1e156047bf96befb@[::]:3033? discport=0" INFO [03-06|05:26:44] IPC endpoint opened url=/root/privatechain/data0/geth.ipc INFO [03-06|05:26:44] HTTP Endpoint Opened URL =http://127.0.0.1:8545 cors= vhosts=localhost Welcome to the Geth JavaScript Console! instance: Geth/TestNode/v1.8.2 - unstable - 0 b814d32 / Linux - amd64 / go1.9.4 INFO [03-06 | 05:26:44] Etherbase automatically configured address=0xFc2D11A7A4408b77d95202c0A455cfd44F2A4cFD coinbase: 0xfc2d11a7a4408b77d95202c0a455cfd44f2a4cfd at block: 0 (Thu, 01 Jan 1970 00:00:00 UTC) datadir: /root/privatechain/data0 modules: Admin :1.0 Debug :1.0 ETH :1.0 Miner :1.0 NET :1.0 personal:1.0 RPC :1.0 TXPool :1.0 web3:1.0Copy the code
It’s almost up and running
Other, refer to the https://g2ex.github.io/2017/09/12/ethereum-guidance/