windows geth 搭建以太坊私有链
{ "config": { "chainId": 10, "homesteadBlock": 0, "eip155Block": 0, "eip158Block": 0 }, "coinbase" : "0x3df788e49de9c627f52a3f236dd9be2bd9456ad5", "difficulty" : "0x20000", "extraData" : "", "gasLimit" : "0x2fefd8", "nonce" : "0x0000000000000042", "mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000", "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", "timestamp" : "0x00", "alloc" : { "0x3df788e49de9c627f52a3f236dd9be2bd9456ad5": { "balance": "30000000000000000000000" }, "0xc4be8badcaca9dbf5b45a22f400dbc0070179f02": { "balance": "40000000000000000000000" } } }我的genesis.json,预先给自己的测试账号分配了一些以太币,这样就不用挖矿了。
初始化区块链geth --datadir ~/privnet/ init genesis.json
文件在F:userprofileprivnet下
geth --datadir ~/privnet --networkid 89120348581
3、创建私有链:参考http://blog.csdn.net/sportshark/article/details/51855007
(1)geth启动成功后,重新开一个终端,执行以下命令,打开geth控制台:
geth --dev console 2>>file_to_log_output
geth -datadir "%cd%chain" console
该命令会打开geth控制台,同时在目录下生成一个叫做file_to_log_output的日志文件,等下我们会来查看这个日志文件。
(2)查看当前有哪些账户
eth.accounts 可见当前没有任何账户。
(3)创建一个新账户
personal.newAccount(‘123456")
eth.getBalance("0xbcf5b841303bc08026ce2d3b8f83498ffe42c12f")
eth.getBalance("0xb8b12a801b610176935a15321f77b48dd5c0c448")
每个账户的公钥(地址)是一切以太坊账户操作的核心,但地址字符串太长,我们用acc0/acc1 分别代表accounts[0]和[1],另外设置要转移0.01个以太币
> acc0 = eth.accounts[0]
"0xbcf5b841303bc08026ce2d3b8f83498ffe42c12f"
> acc1 = eth.accounts[1]
"0xb8b12a801b610176935a15321f77b48dd5c0c448"
> amount = web3.toWei(0.01)
"10000000000000000"
这个时候我们可以使用eth.sendTransaction来将0.01个以太币从acc0转移到acc1中。
> eth.sendTransaction({from: acc0, to: acc1, value: amount})
1)初始以太坊
D:lock chaingeth>geth init genesis.json
2)启动以太坊
geth --rpc --rpcapi personal,db,eth,net,web3 --networkid 666666 console
--rpc Enable the HTTP-RPC server
--rpcapi API"s offered over the HTTP-RPC interface
--networkid 区块链ID-私链
--console 命令行模式
3)创建钱包
personal.newAccount("enter your password")
手动打开钱包,出现PRIVATE字样
# 开始挖矿 (一个线程挖矿,多线程会很卡)
> miner.start(1)
会发现钱包余额不停地变化,cmd里也在不停地挖矿,哈哈,流程通了
Deploy
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: Java实现--登录和注册案例(IO流实现)
- 下一篇: nctf-web