aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/mist/assets/ext/example/balance.html
blob: 88f55315a89d8bcc212d4ba885ec533c85a4f80f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<!doctype>
<html>

<head>
<script type="text/javascript" src="js/bignumber.js/bignumber.min.js"></script>
<script type="text/javascript" src="../dist/ethereum.js"></script>
<script type="text/javascript">
   
    var web3 = require('web3');
    web3.setProvider(new web3.providers.HttpSyncProvider('http://localhost:8080'));

    function watchBalance() {
        var coinbase = web3.eth.coinbase;
        var originalBalance = 0;

        var balance = web3.eth.balanceAt(coinbase);
        var originalBalance = web3.toDecimal(balance);
        document.getElementById('original').innerText = 'original balance: ' + originalBalance + '    watching...';

        web3.eth.watch({altered: coinbase}).changed(function() {
            balance = web3.eth.balanceAt(coinbase)
            var currentBalance = web3.toDecimal(balance);
            document.getElementById("current").innerText = 'current: ' + currentBalance;
            document.getElementById("diff").innerText = 'diff:    ' + (currentBalance - originalBalance);
        });
    }

</script>
</head>
<body>
    <h1>coinbase balance</h1>
    <button type="button" onClick="watchBalance();">watch balance</button>
    <div></div>
    <div id="original"></div>
    <div id="current"></div>
    <div id="diff"></div>
</body>
</html>