Windows搭建以太坊私有链
第一步: 软件安装
我们需要安装geth软件,以及初始化区块的配置文件。
下载地址 链接:https://pan.baidu.com/s/1htSgiUC 密码:ph8o
windows搭建以太坊的私有区块链
一、下载和安装: 1、下载
? 2、安装:比如安装到 D://Environment//Ethereum 目录中 ? 安装完成之后的目录结构
? 3、CMD进入终端 ? geth -help (geth -h)
二、创建创世区块 1、拷贝sspgenesis.json 到 安装目录中 (D://Environment//Ethereum) 2、在CMD 终端,进入到安装目录中
cd D:\Environment\Ethereum
geth --datadir "D://Environment//Ethereum//ichain" init sspgenesis.json
3、启动命令
这一步仍然是在 D://Environment//Ethereum 目录下
geth --identity "niubit" --rpc --rpcaddr "0.0.0.0" --port 30303 --rpccorsdomain "*" --datadir "cdata" --networkid 999 --rpcport 9090 console
4、后续的启动
后续的启动,可以使用简单一些的命令,不必指定端口号、目录等;(console表示将日志输出到控制台中)
geth -datadir "D://Environment//Ethereum" console
三、常用命令
geth 和 eth geth 命令为服务端命令 eth 命令为客户端命令
> personal.newAccount()
Passphrase: tju1895
Repeat passphrase: tju1895
"0x78300df230c42f2ad8feb5e7ed037b06a5894f10"
exit
> eth.accounts[0]
"0x78300df230c42f2ad8feb5e7ed037b06a5894f10"
> eth.accounts
["0x78300df230c42f2ad8feb5e7ed037b06a5894f10"]
eth.getBalance(user1)
> eth.getBalance("0x78300df230c42f2ad8feb5e7ed037b06a5894f10")
0
eth.blockNumber
miner.start()
miner.stop()
# 再创建一个用户user2
> personal.newAccount()
Passphrase:
Repeat passphrase:
"0xa8f32b62c5cf44fc3acc6b4c1153022854da84a8"
# user1
"0x78300df230c42f2ad8feb5e7ed037b06a5894f10"
user1 = eth.accounts[0]
user2 = eth.accounts[1]
# 转账
eth.sendTransaction({from:user1, to:user2, value:web3.toWei(3, "ether")})
eth.sendTransaction({from:"0xa8f32b62c5cf44fc3acc6b4c1153022854da84a8", to:"0x78300df230c42f2ad8feb5e7ed037b06a5894f10", value:web3.toWei(0, "ether")})
# 解锁账号
personal.unlockAccount(user1, "密码")
> personal.unlockAccount(user1, "tju1895")
true
>
true
# 查看自己节点的信息
admin.nodeInfo
> admin.nodeInfo
{
enode: "enode://83f67341936dca4e3597f86e5da499bf811111b0933c82d5f6b2c33daf94671b7d2ea74a87c934eea9766d7b7a7f848d6a5cb0d57ad3bc88f7e8dee5275b05ff@[::]:30303",
id: "83f67341936dca4e3597f86e5da499bf811111b0933c82d5f6b2c33daf94671b7d2ea74a87c934eea9766d7b7a7f848d6a5cb0d57ad3bc88f7e8dee5275b05ff",
ip: "::",
listenAddr: "[::]:30303",
name: "Geth/v1.7.0-stable-6c6c7b2a/windows-amd64/go1.9",
ports: {
discovery: 30303,
listener: 30303
},
protocols: {
eth: {
difficulty: 17179869184,
genesis: "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
head: "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
network: 1
}
}
}
# 添加节点
> admin.addPeer("enode://1e3c1727cd3bee9f25edeb5dbb3b880e03e41f8eec99566557f3ee0422734a8fcad17c161aa93d61bdbfb28ed152c143c7eb501db58bc63502a104a84b62d742@192.168.1.102:30303")
true
# 查看添加新节点的信息 ?空?
admin.peers
#将wei转换为ether
> web3.fromWei(21000000000000, 'ether')
"0.000021"
#检查交易池
txpool.status
#查看正在交易的数据
eth.getBlock("pending",true).transactions
#获取某个区块的信息
eth.getBlock(294)
#gas
eth.estimateGas({from:eth.accounts[1], to: eth.accounts[2], value:50000000000000})
eth.gasPrice
区块链教程—以太坊(一):Windows搭建以太坊私有链 - 知乎 (zhihu.com)
区块链教程—以太坊(二):创建第一个区块链应用_慕课手记 (imooc.com)
区块链教程—以太坊(三):应用代码解析_慕课手记 (imooc.com)
|