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

原文地址:https://blog.csdn.net/jerry81333/article/details/55748747

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中输入:

[html]  view plain  copy
  1. set-ExecutionPolicy RemoteSigned  

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

[html]  view plain  copy
  1. iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex  
4.环境准备,先安装Go语言等前置环境:

[html]  view plain  copy
  1. C:\Windows\system32> choco install git  
  2. C:\Windows\system32> choco install golang  
  3. C:\Windows\system32> choco install mingw  
5.创建工作环境,及克隆源:

[html]  view plain  copy
  1. C:\Users\xxx> set "GOPATH=%USERPROFILE%"  
  2. C:\Users\xxx> set "Path=%USERPROFILE%\bin;%Path%"  
  3. C:\Users\xxx> setx GOPATH "%GOPATH%"  
  4. C:\Users\xxx> setx Path "%Path%"  
  5. C:\Users\xxx> mkdir src\github.com\ethereum  
  6. C:\Users\xxx> git clone https://github.com/ethereum/go-ethereum src\github.com\ethereum\go-ethereum  
  7. C:\Users\xxx> cd src\github.com\ethereum\go-ethereum  
  8. C:\Users\xxx> go get -u -v golang.org/x/net/context  
6.安装geth:

[html]  view plain  copy
  1. C:\Users\xxx\src\github.com\ethereum\go-ethereum> go install -v ./...  

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


Geth:

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

创建测试用私有链:

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

[html]  view plain  copy
  1. C:\Users\XXX:  

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

[html]  view plain  copy
  1. {  
  2.   
  3.     "nonce":"0x0000000000000042",  
  4.   
  5.     "mixhash":"0x0000000000000000000000000000000000000000000000000000000000000000",  
  6.   
  7.     "difficulty": "0x4000",  
  8.   
  9.     "alloc": {},  
  10.   
  11.     "coinbase":"0x0000000000000000000000000000000000000000",  
  12.   
  13.     "timestamp": "0x00",  
  14.   
  15.     "parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000",  
  16.   
  17.     "extraData": "PICC GenesisBlock",  
  18.   
  19.     "gasLimit":"0xffffffff"  
  20.   
  21. }  

2.初始化一条私有链:

[html]  view plain  copy
  1. geth --datadir "%cd%\chain" init piccgenesis.json  
3.运行并进入该私有链的控制台:

[html]  view plain  copy
  1. geth --identity "PICCetherum" --rpc --rpccorsdomain "*" --datadir "%cd%\chain" --port "30303"  --rpcapi "db,eth,net,web3" --networkid 95518 console  

控制台基本操作:

1.查询账户:

[html]  view plain  copy
  1. eth.accounts  
2.创建账户,密码为“123456”:

[html]  view plain  copy
  1. personal.newAccount('123456')  
3.账户赋值给变量:

[html]  view plain  copy
  1. user1 =eth.accounts[0]  
4.查询账户余额:

[html]  view plain  copy
  1. eth.getBalance(user1)  
5.显示当前区块:

[html]  view plain  copy
  1. eth.blockNumber  
6.开始挖矿(默认第一个账户得到挖矿收益):

[html]  view plain  copy
  1. miner.start()  
7.停止挖矿:

[html]  view plain  copy
  1. miner.stop()  
8.解锁账户(获得账户使用权):

[html]  view plain  copy
  1. personal.unlockAccount(user1, "123456")  
9.user1转账3以太币给user2:

[html]  view plain  copy
  1. eth.sendTransaction({from: user1, to: user2, value: web3.toWei(3,"ether")})  

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值