以太坊查看帳戶餘額

若是你但願立刻開始學習以太坊DApp開發,能夠訪問匯智網提供的出色的在線互動教程:web

使用web3獲取帳戶餘額

可使用JavaScript API來獲取以太坊帳戶餘額,例如在JavaScript代碼中:學習

web3.fromWei(web3.eth.getBalance(web3.eth.coinbase));

若是你在geth控制檯裏,能夠將web3.eth使用其eth別名代替:ui

> web3.fromWei(eth.getBalance(eth.coinbase));

合約中獲取帳戶餘額

在合約中更簡單,Solidity爲每一個address對象都提供了一個balance屬性,它返回以wei爲單位的帳戶餘額。例如:3d

contract ownerbalancereturner {
    address owner;
    function ownerbalancereturner() public {
        owner = msg.sender; 
    }
    function getOwnerBalance() constant returns (uint) {
        return owner.balance;
    }
}
相關文章
相關標籤/搜索