在私有链中转账、挖矿

  1. 创建自己的私有链条
geth --datadir "./" --nodiscover console 2>>geth.log
  1. 创建测试账户
personal.newAccount("123")

其中的 "0x96f1882b48ea8fc99947c838a7637eb1fabd39e2" 是公钥也是交易的账户,私钥在keystore文件夹中以 UTC-- 开头的文件中,私钥被密码 123 加密了。在公网环境下,私钥是至关重要的,不要泄露了自己的私钥。

重复操作创建第二个账户
查看账户

eth.accounts

3.挖矿,默认使用第一个账户 eth.accounts[0] 挖矿

miner.start()

此时可以另起一个终端查看 geth 的运行日志

tail -f geth.log

一段时间后,查看账户余额

acc0 = eth.accounts[0]
eth.getBalance(acc0)

停止挖矿

miner.stop()
在私有链中转账、挖矿_第1张图片

4 . 转账
转账前余额查询

web3.fromWei(eth.getBalance(eth.accounts[0]))

web3.fromWei将数字从单位Wei转化为ether, 1 ether = 1,000,000,000,000,000,000 wei


从eth.accounts[0]中,转账0.98个ether到eth.accounts[1]中

amount = web3.toWei(0.98)
eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], value: amount})

在私有链中转账、挖矿_第2张图片

转账失败,提示 password or unlock,转账前,转出账户需要解锁

personal.unlockAccount(eth.accounts[0])

输入创建账户时的密码后,解锁成功,重新转账。



装张成功,查询账户余额


你可能感兴趣的:(在私有链中转账、挖矿)