quorum/example/balance.html

42 lines
1.3 KiB
HTML
Raw Normal View History

2014-09-30 13:51:53 -07:00
<!doctype>
<html>
<head>
<script type="text/javascript" src="js/es6-promise/promise.min.js"></script>
<script type="text/javascript" src="../dist/ethereum.js"></script>
2014-09-30 13:51:53 -07:00
<script type="text/javascript">
2014-11-13 10:28:58 -08:00
2014-11-12 19:21:51 -08:00
var web3 = require('web3');
web3.setProvider(new web3.providers.AutoProvider());
2014-11-13 10:28:58 -08:00
function watchBalance() {
var coinbase = web3.eth.coinbase;
var originalBalance = 0;
web3.eth.balanceAt(coinbase).then(function (balance) {
originalBalance = web3.toDecimal(balance);
document.getElementById('original').innerText = 'original balance: ' + originalBalance + ' watching...';
});
web3.eth.watch({altered: coinbase}).changed(function() {
web3.eth.balanceAt(coinbase).then(function (balance) {
var currentBalance = web3.toDecimal(balance);
document.getElementById("current").innerText = 'current: ' + currentBalance;
document.getElementById("diff").innerText = 'diff: ' + (currentBalance - originalBalance);
2014-11-12 19:21:51 -08:00
});
2014-11-03 08:46:56 -08:00
});
2014-11-12 19:21:51 -08:00
}
2014-09-30 13:51:53 -07:00
2014-11-13 10:28:58 -08:00
</script>
</head>
2014-09-30 13:51:53 -07:00
<body>
2014-11-14 04:11:47 -08:00
<h1>coinbase balance</h1>
2014-11-13 10:28:58 -08:00
<button type="button" onClick="watchBalance();">watch balance</button>
2014-11-12 19:21:51 -08:00
<div></div>
2014-11-13 10:28:58 -08:00
<div id="original"></div>
<div id="current"></div>
<div id="diff"></div>
2014-09-30 13:51:53 -07:00
</body>
</html>
2014-11-12 19:21:51 -08:00