Geth的安装与配置(Windows版)
Geth的安装与配置(Windows版)
目录
- Geth的安装与配置(Windows版)
- 1.下载
- 2.安装
- 3.配置Geth私网运行
- (1)创建genesis.json
- (2)Geth初始化
- (3)启动Geth
- (4)创建账户
- (5)启动自动密码模式
- 4.Geth的简单操作指令
- (1)账户操作
- (2)区块操作
1.下载
Go-ethereum,也就是Geth,下载地址为:https://geth.ethereum.org/downloads/
2.安装
windows下正常安装
路径设置为:C:\Users\username\geth\
确认路径:
where geth
C:\Users\tangyao\geth\geth.exe
3.配置Geth私网运行
(1)创建genesis.json
在geth文件夹下创建private_net文件夹用于保存,在private_net下创建genesis.json,代码如下:
{"config":{"chainId": 33,"homesteadBlock": 0,"eip150Block": 0,"eip155Block": 0,"eip158Block": 0},"nonce": "0x0000000000000033","timestamp": "0x0","parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000","gaslimit": "0x8000000","difficulty": "0x100","mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000","coinbase": "0x3333333333333333333333333333333333333333","alloc": {}
}
(2)Geth初始化
Windows版:
geth --datadir C:\users\tangyao\geth\private_net init C:\users\tangyao\geth\private_net\genesis.json
(3)启动Geth
geth --networkid "10" --nodiscover --datadir H:\geth\private_net --rpc --rpcaddr "localhost" --rpcport "8545" --rpccorsdomain "*" --rpcapi "eth,net,web3,personal" --allow-insecure-unlock --targetgaslimit "20000000" console 2>> H:\geth\private_net\error.log
成功启动:
Welcome to the Geth JavaScript console!instance: Geth/v1.9.25-stable-e7872729/windows-amd64/go1.15.6
at block: 0 (Thu Jan 01 1970 08:00:00 GMT+0800 (CST))
datadir: H:\geth\private_net
modules: admin:1.0 debug:1.0 eth:1.0 ethash:1.0 miner:1.0 net:1.0 personal:1.0
rpc:1.0 txpool:1.0 web3:1.0
关闭Geth:> exit
(4)创建账户
启动Geht后,准备密码字符串,使用 personal.newAccount(string)
指令创建账户:
> personal.newAccount("password")
"0xbdcfef6cede1108e7d716c0124755a98b9126657"
> personal.newAccount("password")
"0x25f904a59b41f5448120e0aae576e7575b0a0577"
> personal.newAccount("password")
"0x1f47f0c4d9b259d05697840b979c5789a149c0e7"
其中 “0xbdcfef6cede1108e7d716c0124755a98b9126657” 为生成的外部账户地址, “password” 作为密码解锁该账户,一定要记好。
生成多个账户用于操作使用,记录好相应的地址和密码。
(5)启动自动密码模式
在一些账户操作时,比如转账,需要输入密码验证,比较麻烦。通过配置密码文件,可以启动免输入密码的模式。
配置密码文件: 在private_net文件夹下创建文件名为password.txt的文件,在文件中按顺序分别换行输入各个账户的密码。
进行解锁设置并启动Geth:
geth --networkid "10" --nodiscover --datadir H:\geth\private_net --rpc --rpcaddr "localhost" --rpcport "8545" --rpccorsdomain "*" --rpcapi "eth,net,web3,personal" --allow-insecure-unlock --targetgaslimit "20000000" console 2>> H:\geth\private_net\error.log --unlock 0xbdcfef6cede1108e7d716c0124755a98b9126657,0x25f904a59b41f5448120e0aae576e7575b0a0577,0x1f47f0c4d9b259d05697840b979c5789a149c0e7 --password H:\geth\private_net\password.txt
再进行转账等操作,则无需输入密码了。
4.Geth的简单操作指令
(1)账户操作
- 查询账户:
eth.accounts
> eth.accounts
["0xbdcfef6cede1108e7d716c0124755a98b9126657","0x25f904a59b41f5448120e0aae576e7575b0a0577","0x1f47f0c4d9b259d05697840b979c5789a149c0e7"]
- 标记账户:
eth.accounts[ ]
> eth.accounts[0]
"0xbdcfef6cede1108e7d716c0124755a98b9126657"
- 确认coinbase账户:
eth.coinbase
> eth.accounts[0]
"0xbdcfef6cede1108e7d716c0124755a98b9126657"
> eth.coinbase
"0xbdcfef6cede1108e7d716c0124755a98b9126657"
- 变更coinbase账户:
miner.setEtherbase(eth.accounts[ ])
> miner.setEtherbase(eth.accounts[1])
true
> eth.coinbase
"0x25f904a59b41f5448120e0aae576e7575b0a0577"
- 查询账户余额:
eth.getBalance(eth.accounts[])
> eth.getBalance(eth.accounts[0])
90000000000000000000
- 默认以ether显示,数值比较大,可通过
web3.fromWei( ,"ether")
进行单位转化:
> web3.fromWei(eth.getBalance(eth.accounts[0]),"ether")
105
- 普通转账:
eth.sendTransaction({from:eth.accounts[],to:eth.accounts[],value:web3.toWei(n,"ether")})
n为转账数量。返回交易哈希。
> eth.sendTransaction({from:eth.accounts[0],to:eth.accounts[1],value:web3.toWei(5,"ether")})
"0x9d04784d1c674628602edeb76798819dba190d9a76b6ca18fd64175de308665d"
(2)区块操作
- 开始挖矿:
miner.start(1)
括号内的数字代表挖矿操作的线程数 - 确认挖矿状态:
eth.mining
- 停止挖矿:
miner.stop()
> miner.start(1)
null
> eth.mining
true
> miner.stop()
null
- 查询区块:
eth.getBlock()
以太坊的区块数据结构如下:(创世区块,不包含交易和叔区块)
> eth.getBlock(0)
{difficulty: 256,extraData: "0x",gasLimit: 134217728,gasUsed: 0,hash: "0x5704d029fe80f4fb605c0cb5e31d591511f10a46a0cb8166f97d8d559f9bc5b0",logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",miner: "0x3333333333333333333333333333333333333333",mixHash: "0x0000000000000000000000000000000000000000000000000000000000000000",nonce: "0x0000000000000033",number: 0,parentHash: "0x0000000000000000000000000000000000000000000000000000000000000000",receiptsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",size: 507,stateRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",timestamp: 0,totalDifficulty: 256,transactions: [],transactionsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",uncles: []
}
- 查询交易:
eth.getTransaction()
交易的数据结构如下:
> eth.getTransaction("0x9d04784d1c674628602edeb76798819dba190d9a76b6ca18fd64175de308665d")
{blockHash: "0xddea639b05f4a3ebac609e436e72f1c7882cf54772e6af086f31b0431d6b63b2",blockNumber: 63,from: "0xbdcfef6cede1108e7d716c0124755a98b9126657",gas: 21000,gasPrice: 1000000000,hash: "0x9d04784d1c674628602edeb76798819dba190d9a76b6ca18fd64175de308665d",input: "0x",nonce: 0,r: "0x9b82fc5257f7f67d353870f1ad0150cd94f7ac22112314113507cc63c1a5a5eb",s: "0x43ae5331e55c82995c67a6ba03d29c0bb0002286025ee8a73530876fc0fdd169",to: "0x25f904a59b41f5448120e0aae576e7575b0a0577",transactionIndex: 0,v: "0x66",value: 5000000000000000000
}
- 查询交易回执Transaction Receipt:
eth.getTransactionReceipt()
Transaction Receipt数据结构如下:
> eth.getTransactionReceipt("0x9d04784d1c674628602edeb76798819dba190d9a76b6ca18fd64175de308665d")
{blockHash: "0xddea639b05f4a3ebac609e436e72f1c7882cf54772e6af086f31b0431d6b63b2",blockNumber: 63,contractAddress: null,cumulativeGasUsed: 21000,from: "0xbdcfef6cede1108e7d716c0124755a98b9126657",gasUsed: 21000,logs: [],logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",root: "0xb2148d8f70560dc109b105c93f3f52914ee27a283dd0e3121dcd7831b54289bb",to: "0x25f904a59b41f5448120e0aae576e7575b0a0577",transactionHash: "0x9d04784d1c674628602edeb76798819dba190d9a76b6ca18fd64175de308665d",transactionIndex: 0
}
Geth的安装与配置(Windows版)相关推荐
- esp8266驱动_ESP8266配置windows版
ESP8266配置windows版 esp8266上搭载了cp210x芯片.负责开发板和电脑进行通信, https://cn.silabs.com/developers/usb-to-uart-bri ...
- ffmpeg安装教程(windows版)
本文介绍ffmpeg详细安装教程(windows版),附加一个使用的小案例 1.官网下载ffmpeg 进入Download FFmpeg网址,点击下载windows版ffmpeg(点击左下第一个绿色的 ...
- JDK8下载及安装教程之windows版、linux版
JDK8下载及安装教程之windows版.linux版 JAVA8下载及安装教程之windows版 环境: 下载: 安装: JAVA8下载及安装教程之linux版本 环境: 下载: 安装: JAVA8 ...
- windows虚拟机_[安装实录]如何在 Vmware虚拟机中安装 macOS Mojave -- Windows 版
Note: 由于 Github 作者删除了破解的文件,现在该安装方法暂时无效.感谢知友西岚有提出一个解决线索,我对 github 不熟,暂时还未能测试.如果你也碰到类似的问题,可以尝试先按照西岚的方法 ...
- vim win装_vim插件管理器的安装和配置-windows
# vim插件管理器的安装和配置-windows ### 前言 ----------------------------- - vim做一框功能强大的编辑器,扩展功能令人称奇,插件机制非常灵活 - 本 ...
- FasterRunner安装教程(Windows版)
FasterRunner安装教程(Windows版) 原创 幼儿园二园长 发布于2019-05-10 17:02:59 阅读数 499 收藏 更新于2019-05-10 17:04:23 分类专栏: ...
- 视频教程-MCSE 2012之410视频课程:安装和配置Windows Server 2012 R2-微软认证
MCSE 2012之410视频课程:安装和配置Windows Server 2012 R2 13年的IT职业教育经验,10年的企业培训及项目经验.深得广大企业及学员喜爱.曾连续三年获得湖北省IT职业教 ...
- MySQL的安装与配置--windows下安装
转自:https://www.cnblogs.com/winton-nfs/p/11524007.html 免安装版的Mysql MySQL关是一种关系数据库管理系统,所使用的 SQL 语言是用于访问 ...
- Oracle instant client安装与设置 - Windows版,可用WIN7
1.下载 到http://www.oracle.com/technology/software/tech/oci/instantclient/index.html下载符合自己版本的安装程序. 2.解压 ...
最新文章
- Mysql 主从延时监控(pt-heartbeat)详解
- Delphi 与 DirectX 之 DelphiX(33): TDIB.SmoothRotateWrap();
- PowerDesigner中的对象与关系映射建模
- oracle rollup 排序,Oracle教程之rollup用法
- Java基础学习总结(172)——手写Java 重试机制
- 电商项目--使用GitHub进行版本管理,完美衔接idea详细流程,Java初阶知识点,完整步骤
- MMIO与PIO区别
- 双线macd指标参数最佳设置_手机mt4平台怎么使用macd双线指标
- java 定时关机_java实现电脑定时关机的方法
- IT桌面运维常识系列 -(Windows部署服务 - 01)
- kafka及可视化工具offset explorer
- h5页面 请在微信客户端打开链接_使用Fiddler抓包解决“请在微信客户端打开链接”的问题...
- [C++]一个拥有音乐播放器所有基本功能的音乐库
- excel拆分单元格内容_Excel中最神奇的一个快捷键!牛!!
- win7临时文件_小甲办公 | 如何在2020年优雅地使用win7
- 如果删掉微信中一个功能,你的选择是什么
- ElasticSearch7 集群安装和配置
- 如何有效实现软件的需求管理 - 1
- 郊区春游(状压DP水题)+ 记录路径
- Android 上实现非root的 Traceroute -- 非Root权限下移植可执行二进制文件 脚本文件