1 Ubuntu用户可以选择在线安装geth的方式,在终端中依次执行以下命令即可:
$ sudo add-apt-repository -y ppa:ethereum/ethereum
$ sudo apt-get update
$ sudo apt-get install ethereum
安装完成后就用geth help验证是否安装成功
ubuntu@i-umw7lzvn:~$ geth help
NAME:
geth - the go-ethereum command line interface
Copyright 2013-2017 The go-ethereum Authors
USAGE:
geth [options] command [command options] [arguments...]
VERSION:
**1.6.6-stable-10a45cb5**
COMMANDS:
init Bootstrap and initialize a new genesis block
import Import a blockchain file
```
2 下面开始建立私有以太坊网络:以太坊节点之间能够互相链接需要满足1)相同的协议版本2)相同的networkid,所以搭建私有网络最方便的方法就是通过geth命令中的–networkid选项,设置一个与主网不同的networkid(主网的networkid为1),这也是官方推荐的
ubuntu@i-umw7lzvn:~$ mkdir private-geth
ubuntu@i-umw7lzvn:~$ cd private-geth/
世纪区块文件,是一个json格式的文件:vim genesis.json
以太坊支持自定义创世区块,要运行私有链,我们就需要定义自己的创世区块,创世区块信息写在一个json格式的配置文件中。首先将下面的内容保存到一个json文件中,例如genesis.json(涉及到权限问题所以进入root权限)
root@i-nhmyceuh:/home/ubuntu/private-geth# vim genesis.json
{
"config": {
"chainId": 15,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"coinbase" : "0x0000000000000000000000000000000000000000",
"difficulty" : "0x40000",
"extraData" : "",
"gasLimit" : "0xffffffff",
"nonce" : "0x0000000000000042",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00",
"alloc": { }
}
准备好创世区块配置文件后,需要初始化区块链,将上面的创世区块信息写入到区块链中。首先要新建一个目录用来存放区块链数据,假设新建的数据目录为~/private-geth/app/chain,genesis.json保存在~/private-geth中,此时目录结构应该是这样的:
private-geth
├── app
└── genesis.json
接下来进入private-geth中,执行初始化命令:
root@i-nhmyceuh:/home/ubuntu/private-geth# geth --datadir data0 init genesis.json
WARN [06-26|10:54:33] No etherbase set and no accounts found as default
INFO [06-26|10:54:33] Allocated cache and file handles database=/home/ubuntu/private-geth/data0/geth/chaindata cache=16 handles=16
INFO [06-26|10:54:33] Writing custom genesis block
INFO [06-26|10:54:33] Successfully wrote genesis state database=chaindata hash=a0e580鈥5e82e
INFO [06-26|10:54:33] Allocated cache and file handles database=/home/ubuntu/private-geth/data0/geth/lightchaindata cache=16 handles=16
INFO [06-26|10:54:33] Writing custom genesis block
INFO [06-26|10:54:33] **Successfully** wrote genesis state database=lightchaindata hash=a0e580鈥5e82e
初始化成功后,会在数据目录app/cahin中生成geth和keystore两个文件夹,此时目录结构如下:
root@i-nhmyceuh:/home/ubuntu/private-geth# cd data0/
root@i-nhmyceuh:/home/ubuntu/private-geth/data0# ll
total 16
drwx------ 4 root root 4096 Jun 26 10:54 ./
drwxr-xr-x 3 root root 4096 Jun 26 10:54 ../
drwxr-xr-x 4 root root 4096 Jun 26 10:54 geth/
drwx------ 2 root root 4096 Jun 26 10:54 keystore/
其中geth/chaindata中存放的是区块数据,keystore中存放的是账户数据。
启动节点, 加上console 表示启动后,启用命令行:
root@i-nhmyceuh:/home/ubuntu/private-geth/data0# geth --datadir ./data0 --networkid 11 console
WARN [06-26|10:56:58] No etherbase set and no accounts found as default
INFO [06-26|10:56:58] Starting peer-to-peer node instance=Geth/v1.6.6-stable-10a45cb5/linux-amd64/go1.8.1
INFO [06-26|10:56:58] Allocated cache and file handles database=/home/ubuntu/private-geth/data0/data0/geth/chaindata cache=128 handles=1024
INFO [06-26|10:56:58] Writing default main-net genesis block
INFO [06-26|10:56:59] Initialised chain configuration config="{ChainID: 1 Homestead: 1150000 DAO: 1920000 DAOSupport: true EIP150: 2463000 EIP155: 2675000 EIP158: 2675000 Metropolis: 9223372036854775807 Engine: ethash}"
INFO [06-26|10:56:59] Disk storage enabled for ethash caches dir=/home/ubuntu/private-geth/data0/data0/geth/ethash count=3
INFO [06-26|10:56:59] Disk storage enabled for ethash DAGs dir=/root/.ethash count=2
WARN [06-26|10:56:59] Upgrading db log bloom bins
INFO [06-26|10:56:59] Bloom-bin upgrade completed elapsed=71.646碌s
INFO [06-26|10:56:59] Initialising Ethereum protocol versions="[63 62]" network=11
INFO [06-26|10:56:59] Loaded most recent local header number=0 hash=d4e567鈥b8fa3 td=17179869184
INFO [06-26|10:56:59] Loaded most recent local full block number=0 hash=d4e567鈥b8fa3 td=17179869184
INFO [06-26|10:56:59] Loaded most recent local fast block number=0 hash=d4e567鈥b8fa3 td=17179869184
INFO [06-26|10:56:59] Starting P2P networking
INFO [06-26|10:57:01] UDP listener up self=enode://51ebb32b131ac52c9caca88396a3d0f77f89bd4cfceb9f59bca6615557d5f7b6333cdfad20ec2d1bb26feb211e0abf8ba11a1a1e9c3f4d2987aca4be7e855020@[::]:30303
INFO [06-26|10:57:01] RLPx listener up self=enode://51ebb32b131ac52c9caca88396a3d0f77f89bd4cfceb9f59bca6615557d5f7b6333cdfad20ec2d1bb26feb211e0abf8ba11a1a1e9c3f4d2987aca4be7e855020@[::]:30303
INFO [06-26|10:57:01] IPC endpoint opened: /home/ubuntu/private-geth/data0/data0/geth.ipc
Welcome to the Geth JavaScript console!
instance: Geth/v1.6.6-stable-10a45cb5/linux-amd64/go1.8.1
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.0
```
```
查看账户
> eth.accounts
[]
创建账户密码为123
> personal.newAccount("123")
"0x04db853fe43494022f7f961091c1764709aa5f87"
> INFO [06-26|10:57:57] New wallet appeared url=keystore:///home/ubuntu/private鈥[32mstatus=Locked
开始挖矿
> miner.start()
INFO [06-26|10:14:06] Updated mining threads threads=0
INFO [06-26|10:14:06] Transaction pool price threshold updated price=18000000000
INFO [06-26|10:14:06] Starting mining operation
null
> INFO [06-26|10:14:06] Commit new mining work number=1 txs=0 uncles=0 elapsed=444.165碌s
INFO [06-26|10:14:10] Generating DAG in progress
原文:https://blog.csdn.net/DDFFR/article/details/73733850
分享一些区块链教程:
php比特币开发教程:http://xc.hubwiz.com/course/5b9e779ac02e6b6a59171def,本课程面向初学者,内容即涵盖比特币的核心概念,例如区块链存储、去中心化共识机制、密钥与脚本、交易与UTXO等,同时也详细讲解如何在Php代码中集成比特币支持功能,例如创建地址、管理钱包、构造裸交易等,是Php工程师不可多得的比特币开发学习课程。
java和web3j以太坊开发:http://xc.hubwiz.com/course/5b2b6e82c02e6b6a59171de2,主要是针对java和android程序员围绕web3j库进行区块链以太坊开发的讲解。
php以太坊:http://xc.hubwiz.com/course/5b36629bc02e6b6a59171de3,主要是介绍使用php进行智能合约开发交互,进行账号创建、交易、转账、代币开发以及过滤器和事件等内容。
EOS智能合约与DApp开发入门教程:http://xc.hubwiz.com/course/5b52c0a2c02e6b6a59171ded,本课程帮助你快速入门EOS区块链去中心化应用的开发,内容涵盖EOS工具链、账户与钱包、发行代币、智能合约开发与部署、使用代码与智能合约交互等核心知识点,最后综合运用各知识点完成一个便签DApp的开发。
python以太坊:http://xc.hubwiz.com/course/5b40462cc02e6b6a59171de4,主要是针对python围绕web3.py进行区块链以太坊应用开发的讲解。
C#以太坊:http://xc.hubwiz.com/course/5b6048c3c02e6b6a59171dee,主要讲解如何使用C#开发基于.Net的以太坊应用,包括账户管理、状态与交易、智能合约开发与交互、过滤器和事件等。
以太坊开发:http://xc.hubwiz.com/course/5abbb7acc02e6b6a59171dd6,主要是介绍使用node.js、mongodb、区块链、ipfs实现去中心化电商DApp实战,适合进阶。
以太坊教程:http://xc.hubwiz.com/course/5a952991adb3847553d205d1,主要介绍智能合约与dapp应用开发,适合入门。