以太坊学习(1)私有链搭建

以太坊私有链搭建

本文根据汪晓明的视频资料整理,ubuntu16.04测试正确。

代码块

安装go-ethereum客户端

sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo add-apt-repository -y ppa:ethereum/ethereum-dev
sudo apt-get update
sudo apt-get install ethereum

指定工作目录,以防止跟共有链混淆,进入开发模式

geth --datadir "~/pengfan/eth" --dev

另外重新启动一个geth控制台,将日志文件输出到制定文件中,

geth --dev console 2>>file_to_log_output
Welcome to the Geth JavaScript console!

instance: Geth/v1.5.5-stable-ff07d548/linux/go1.7.3
 modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 shh:1.0 txpool:1.0 web3:1.0

重新启动一个窗口,输出日志文件

tail -f file_to_log_output

添加用户,指定密码

> eth.accounts
[]
> personal.newAccount('123456')
"0x3daef47c6c40b25ebb720ab6313947b069568b54"
> eth.accounts
["0x3daef47c6c40b25ebb720ab6313947b069568b54"]
> personal.newAccount('123456')
"0x51366d4f2d9209c0d776df6ae10dff051d6a1acb"
> user1=eth.accounts[0]
"0x3daef47c6c40b25ebb720ab6313947b069568b54"
> user1
"0x3daef47c6c40b25ebb720ab6313947b069568b54"
> user2=eth.accounts[1]
"0x51366d4f2d9209c0d776df6ae10dff051d6a1acb"
> user2
"0x51366d4f2d9209c0d776df6ae10dff051d6a1acb"

查询余额和区块号

> eth.getBalance(user1)
0
> eth.getBalance(user2)
0
> eth.blockNumber
0

开始挖矿

> miner.start()
true
> eth.getBalance(user1)
15000000000000000000
> eth.getBalance(user2)
0
> miner.stop()
true
> eth.blockNumber
3

解锁账户

>eth.sendTransaction({from:user1,to:user2,value:web3.toWei(3,"ether")})
Error: account is locked
    at web3.js:3119:20
    at web3.js:6023:15
    at web3.js:4995:36
    at <anonymous>:1:1

> eth.accounts
["0x3daef47c6c40b25ebb720ab6313947b069568b54", "0x51366d4f2d9209c0d776df6ae10dff051d6a1acb"]
>personal.unlockAccount("0x3daef47c6c40b25ebb720ab6313947b069568b54","123456")
true

转账,挖矿确认

>eth.sendTransaction({from:user1,to:user2,value:web3.toWei(3,"ether")})
"0xec8c7a510c217ff2b58a00b0f842e075551d19b615373bccaa61cfeacd3de27b"
> eth.getBalance(user2)
0
> miner.start()
true
> miner.stop()
true
> eth.getBalance(user2)
0
> eth.blockNumber
3
> miner.start()
true
> eth.getBalance(user2)
3000000000000000000
> miner.stop()
true
> eth.blockNumber
4

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值