-
安装:
1: Geth官网: https://geth.ethereum.org/
2: Geth的github: https://github.com/ethereum/go-ethereum -
配置环境变量,将Geth安装目录路径添加到系统变量的Path中,并打开cmd输入下面命令检查geth是否安装成功
geth help
// 检查geth版本
geth version
- 在Geth文件目录下创建genesis.json文件(创建创世区块),并进行以下配置
{
"nonce": "0x0",
"timestamp": "0x5ddf8f3e",
"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x47b760",
"difficulty": "0x00002",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"alloc": { },
"number": "0x0",
"gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"config": {
"chainId": 6500,
"homesteadBlock": 0
}
}
- 初始化区块:在Geth目录下通过cmd执行以下命令创建chain文件夹
geth --datadir chain init genesis.json
- 搭建私有网络
geth --identity "myethereum" --http --http.corsdomain "*" --datadir "chain" --port "30303" --http.api "db,eth,net,web3,personal,miner" --networkid 6500 console 2>1.txt
- 一些基本命令
// 查看当前账户
eth.accounts
// 添加一个账户,括号中为自定义的密码
personal.newAccount("123")
// 查询以太币数量
eth.getBalance(eth.accounts[0])
// 挖矿
miner.start()
// 或者 自定义挖矿数量
miner.start(3)
// 停止挖矿
miner.stop()
// 将Wei单位转换成以太币单位查看当前账户下的以太币
web3.fromWei(eth.getBalance(eth.accounts[0]))
Q.E.D.