If you want to start learning Ethereum DApp development right away, you can visit the excellent online interactive tutorial provided by Huizhi.com:
Get account balance using web3
The Ethereum account balance can be obtained using the JavaScript API, for example in the JavaScript code:
web3.fromWei(web3.eth.getBalance(web3.eth.coinbase));
If you are in the geth console, you can web3.eth
use its eth
alias instead:
> web3.fromWei(eth.getBalance(eth.coinbase));
Get the account balance from the contract
Even simpler in a contract, Solidity address
provides a balance
property for each object wei
that the account balance in units. E.g:
contract ownerbalancereturner {
address owner;
function ownerbalancereturner() public {
owner = msg.sender;
}
function getOwnerBalance() constant returns (uint) {
return owner.balance;
}
}