web3js api reference

James Ray edited this page May 25, 2018 · 4 revisions
Clone this wiki locally

Contents


<!doctype>

<script type="text/javascript" src="../node_modules/bignumber.js/bignumber.min.js"></script> <script type="text/javascript" src="../dist/web3-light.js"></script> <script type="text/javascript">
var Web3 = require('web3');
var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider());
function watchBalance() {
    var coinbase = web3.eth.coinbase;
    var originalBalance = web3.eth.getBalance(coinbase).toNumber();
    document.getElementById('coinbase').innerText = 'coinbase: ' + coinbase;
    document.getElementById('original').innerText = ' original balance: ' + originalBalance + '    watching...';
    web3.eth.filter('latest').watch(function() {
        var currentBalance = web3.eth.getBalance(coinbase).toNumber();
        document.getElementById("current").innerText = 'current: ' + currentBalance;
        document.getElementById("diff").innerText = 'diff:    ' + (currentBalance - originalBalance);
    });
}
</script>

coinbase balance

watch balance
> 1. *** > 1. * `_****_`