1、Geth是什么?
Geth 又名Go Ethereum. 是以太坊协议的三种实现之一,由Go语言开发,完全开源的项目。Geth 可以被安装在很多操作系统上,包括Windows、Linux、Mac的OSX、Android或者IOS系统。
Geth官网:https://geth.ethereum.org/
Geth的Github地址:https://github.com/ethereum/go-ethereum
Geth是以太坊协议的具体落地实现,通过Geth,你可以实现以太坊的各种功能,如账户的新建编辑删除,开启挖矿,ether币的转移,智能合约的部署和执行等等。
2、Geth安装
主要讲解Windows 环境下的Geth安装,下载Windows-Geth安装包直接安装即可:
https://geth.ethereum.org/downloads/
下载后双击安装,安装完成后Geth会自己配置环境变量,
在命令行中执行 geth version 查看到版本即安装成功,如下:
C:\Users\Administrator>geth version Geth Version: 1.8.3-stable Git Commit: 329ac18ef617d0238f71637bffe78f028b0f13f7 Architecture: amd64 Protocol Versions: [63 62] Network Id: 1 Go Version: go1.10 Operating System: windows GOPATH= GOROOT=C:\go
3、使用Geth启动以太坊私有链
新建工作目录文件夹,例如:Gth,在此文件下新建创世块文件: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": { } }
切换回命令行,执行命令,制造创世区块
geth --datadir "./" init genesis.json
创建以太坊私有链
geth --datadir "./" --nodiscover console 2>>geth.log
4、使用Geth对账户进行操作
//查看账户 eth.accounts //新建账户,ruoli为密码 personal.newAccount("ruoli") //查看以太币数量 acc0 = eth.accounts[0] eth.getBalance(acc0) //开始挖矿 miner.start() //停止挖矿 miner.stop()
5、安装Remix
强烈建议新手使用Remix来进行开发,Remix是一个基于浏览器的Solidity编译部署环境,就可以不用安装Solidity,在线Remix连接如下:http://remix.ethereum.org
在线环境由于网络的原因可能打开比较慢,也可以在本地安装Remix,本地源码安装步骤较为复杂,使用源码安装Geth准备工作如下
https://github.com/ethereum/remix-ide
http://nodejs.cn/download/
https://gitforwindows.org/
https://eternallybored.org/misc/wget/
https://www.python.org/downloads/
npm install --global --production windows-build-tools
准备完成后,在Remix源码根目录运行如下命令进行安装:
npm install npm run build npm run serve
启动成功后访问:http://localhost:8080 即可看到本地Remix开发环境。
6、Mist安装
Mist 是以太坊官方提供的浏览器,通过Mist我们可以很方便的连接上我们的私有网络,从而更好的开发、调试、测试我们的智能合约。
下载地址:https://github.com/ethereum/mist/releases/
首先启动Geth:
geth --datadir "./" --nodiscover console 2>>geth.log
然后启动Mist:
'C:\Users\think\Downloads\Ethereum-Wallet-win64-0-10-0\Ethereum Wallet.exe' --rpc "\\.\pipe\geth.ipc"