首页 > 学院 > 开发设计 > 正文

Win10 go-ethereum的安装配置与基本使用教程

2019-11-08 02:36:35
字体:
来源:转载
供稿:网友

go-ethereum

go-ethereum是以太坊的客户端之一,是一个基于Go语言的客户端。以太坊还有别的客户端包括C++,javaScript,python,Java等,比较常用的就是Go语言实现的客户端geth (go-ethereum),其他常用的还有一个叫testrpc的工具, 它使用了Python客户端pyethereum。

Win10配置:

1.打开Powershell,win10自带,Win7版本需要去微软官方下载补丁,是一个类似于Python pip的包管理装置,并需要以管理员身份运行:

2.设置Get-ExecutionPolicy可用,PowerShell中输入:

set-ExecutionPolicy RemoteSigned

3.安装Chocolatey,这是一个第三方的包管理器,官方网址:https://chocolatey.org/

iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex4.环境准备,先安装Go语言等前置环境:

C:/Windows/system32> choco install gitC:/Windows/system32> choco install golangC:/Windows/system32> choco install mingw5.创建工作环境,及克隆源:

C:/Users/xxx> set "GOPATH=%USERPROFILE%"C:/Users/xxx> set "Path=%USERPROFILE%/bin;%Path%"C:/Users/xxx> setx GOPATH "%GOPATH%"C:/Users/xxx> setx Path "%Path%"C:/Users/xxx> mkdir src/github.com/ethereumC:/Users/xxx> git clone https://github.com/ethereum/go-ethereum src/github.com/ethereum/go-ethereumC:/Users/xxx> cd src/github.com/ethereum/go-ethereumC:/Users/xxx> go get -u -v golang.org/x/net/context6.安装geth:

C:/Users/xxx/src/github.com/ethereum/go-ethereum> go install -v ./...

PS:本人配置的时候,不知为何,配置完成后将我原先就有的Python环境完全移除了,也是莫名其妙,这里有Python环境的人要注意下。

Geth:

以开发者的角度,介绍下基本用法:

创建测试用私有链:

1.首先,将自定义的创始区块放入

C:/Users/XXX:

目录下,创始区块必须是.json文件,文件名可自定,这里设置为piccgenesis.json,文件内容如下:

{    "nonce":"0x0000000000000042",    "mixhash":"0x0000000000000000000000000000000000000000000000000000000000000000",    "difficulty": "0x4000",    "alloc": {},    "coinbase":"0x0000000000000000000000000000000000000000",    "timestamp": "0x00",    "parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000",    "extraData": "PICC GenesisBlock",    "gasLimit":"0xffffffff"}

2.初始化一条私有链:

geth --datadir "%cd%/chain" init piccgenesis.json3.运行并进入该私有链的控制台:

geth --identity "PICCetherum" --rpc --rpccorsdomain "*" --datadir "%cd%/chain" --port "30303"  --rpcapi "db,eth,net,web3" --networkid 95518 console

控制台基本操作:

1.查询账户:

eth.accounts2.创建账户,密码为“123456”:

personal.newAccount('123456')3.账户赋值给变量:

user1 =eth.accounts[0]4.查询账户余额:

eth.getBalance(user1)5.显示当前区块:

eth.blockNumber6.开始挖矿(默认第一个账户得到挖矿收益):

miner.start()7.停止挖矿:

miner.stop()8.解锁账户(获得账户使用权):

personal.unlockAccount(user1, "123456")9.user1转账3以太币给user2:

eth.sendTransaction({from: user1, to: user2, value: web3.toWei(3,"ether")})


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表