
上QQ阅读APP看本书,新人免费读10天
设备和账号都新为新人
4.2.1 console中web3对象的命令
eth.accounts函数可以用来获取节点的账户信息,在功能上等同于account list命令,代码如下:

eth.getBalance函数可以用来获取指定账户的余额信息,例如,这里获取账户0x64c3cfed5f8531958cf7484d2fbf60b934dea36c的余额为“0”,代码如下:

web3.fromWei函数用于单位转换,可将wei转为ether、finney等单位。因为10^18 wei=1 ether,所以1000000 wei转为ether后为0.000000000001 ether,代码如下:

web3.toWei函数用于将其他单位转为wei,代码如下:

personal.unlockAccount函数用于解锁账户,账户解锁后才能发送交易,解锁密码为新建账户时设置的密码,代码如下:

eth.blockNumber函数用于显示当前的区块数,因为当前节点还没有区块,所以为“0”,代码如下:

上面介绍了console中的一些基础命令,其他相关命令将配合例子进行讲解。