博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
以太链私有网络(Ethereum Private Networks)的使用
阅读量:7186 次
发布时间:2019-06-29

本文共 2540 字,大约阅读时间需要 8 分钟。

hot3.png

==============================

创建 Private Networks
==============================
1.准备
下载和安装命令行工具geth,;
创建CustomGenesis.json创世区块的配置

{    "nonce": "0x0000000000000042",         "timestamp": "0x0",    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",    "extraData": "0x0",         "gasLimit": "0x8000000",         "difficulty": "0x400",    "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",    "coinbase": "0x3333333333333333333333333333333333333333",         "alloc": {     }}

2.初始化

geth --identity "CSQNodeName" --rpc --rpcport "8080" --rpccorsdomain "*" --datadir ~/.ethereum_private --port "30303" --nodiscover --rpcapi "db,eth,net,web3,personal" --networkid 1999 init /Volumes/disk2/software/blockchain/CustomGenesis.json

3.运行实例 

geth --identity "CSQNodeName" --rpc --rpccorsdomain "*" --datadir ~/.ethereum_private --rpcapi "eth,net,web3,admin,personal" --shh --dev console#如果你想连接Ethereum的测试网络,可运行如下命令geth --testnet --rpc --rpcaddr "127.0.0.1" --rpcport "8545" --rpcapi "db,eth,net,web3" --rpccorsdomain "http://localhost:8000"

4.创建帐号,密码是 123456
>personal.newAccount("123456")
"0x60249051528212bd2fd0e72933b5931836065b56"

5.挖矿
set it as the etherbase:
>miner.setEtherbase(personal.listAccounts[0])
>miner.start()
Automatic pregeneration of ethash DAG ON (ethash dir: ~/.ethash)

#要花费10分钟左右时间,数据保存在~/.ethash目录下,约1G大小。

需要开户另外一个实例才可以结束miner :((Update:可以停止,不用管滚动的屏幕,直接复制miner.stop()粘贴,回车就可以停止挖矿)

>miner.stop()

6.执行多个console

如果实例已经在运行,可以执行 geth attach 使用旧的实例(数据库不能同时服务两个实例)

geth --identity "CSQNodeName" --rpc --rpcport "8080" --rpccorsdomain "*" --datadir ~/.ethereum_private --port "30303" --nodiscover --rpcapi "db,eth,net,web3" --networkid 1999 --ipcpath ~/.ethereum_private/geth.ipc attach

上面的命令在osx下会提示找不到geth.ipc文件的情况,即使指定了ipcpath也不行(可能是geth的bug),它只会去/Users/zhugan/Library/Ethereum/geth.ipc下找, 需要手工修正 ln -s ~/.ethereum_private/geth.ipc ~/.ethereum_private/geth.ipc

查询加载的rpc api模块(这涉及到后面使用wallet是否支持personal协议)

web3.rpc

更多指令参考

7.查询eth余额

balance = web3.fromWei(eth.getBalance(eth.accounts[0]), "ether");

8.用Ethereum Wallet连上私有网络

open -a /Applications/Ethereum\ Wallet.app --args --rpc  ~/.ethereum_private/geth.ipc --rpcapi "eth,web3,personal"

然后可以用Wallet也创建contracts了!(测试发现创建不了合约:The method personal_sendTransaction does not exist/is not available,事实上node有启用personal rpcapi,不知什么原因会提示找不到方法?

获取钱包命令参数

/Applications/Ethereum\ Wallet.app/Contents/MacOS/Ethereum\ Wallet --help

9.参考

  • geth命令参数
  • Ethereum Wallet(Mist)命令参数 
  • web3指令参考

转载于:https://my.oschina.net/swingcoder/blog/793034

你可能感兴趣的文章
匿名函数注入jQuery的作用
查看>>
Linux环境下JDK的安装
查看>>
更改jupyter notebook的主题颜色(theme)
查看>>
转正申请书
查看>>
如何写好一篇让搜索引擎跟用户都喜欢的原创文章
查看>>
用PageOffice实现C#ASP.NET批量转换导出Word文档
查看>>
Matrix 详解
查看>>
初始化Servlet两个init的区别
查看>>
Leetcode PHP题解--D77 812. Largest Triangle Area
查看>>
Linux中Bash的算数运算与Bash配置文件
查看>>
将数据库中的表显示到窗体
查看>>
Cassandra教程(2) ---- Cassandra2.2的新特性
查看>>
/etc/passwd、/etc/shadow、/etc/group每个字段的含义
查看>>
新增TinyMessage,并实现邮件接收处理
查看>>
PHP运行模式总结
查看>>
awk
查看>>
用qmake生成Makefile
查看>>
centos安装bugfree
查看>>
通过exits、getChildren、getData注册的watch有什么不同
查看>>
使用Leopard Redis操作Redis
查看>>