aboutsummaryrefslogtreecommitdiffstats
path: root/example/balance.html
diff options
context:
space:
mode:
authorMarek Kotewicz <marek.kotewicz@gmail.com>2015-01-06 20:27:43 +0800
committerMarek Kotewicz <marek.kotewicz@gmail.com>2015-01-06 20:27:43 +0800
commit8c1b26889ae90211e01ba2c364aa5d245d6f232f (patch)
tree64975dfa81ce5e0d834f925e4cd4789fa7494f08 /example/balance.html
parentaf9242f4cc382a61bea9142ddbd0cec2e1edf08a (diff)
downloadgo-tangerine-8c1b26889ae90211e01ba2c364aa5d245d6f232f.tar
go-tangerine-8c1b26889ae90211e01ba2c364aa5d245d6f232f.tar.gz
go-tangerine-8c1b26889ae90211e01ba2c364aa5d245d6f232f.tar.bz2
go-tangerine-8c1b26889ae90211e01ba2c364aa5d245d6f232f.tar.lz
go-tangerine-8c1b26889ae90211e01ba2c364aa5d245d6f232f.tar.xz
go-tangerine-8c1b26889ae90211e01ba2c364aa5d245d6f232f.tar.zst
go-tangerine-8c1b26889ae90211e01ba2c364aa5d245d6f232f.zip
renamed example/index.html -> example/balance.html
Diffstat (limited to 'example/balance.html')
-rw-r--r--example/balance.html41
1 files changed, 41 insertions, 0 deletions
diff --git a/example/balance.html b/example/balance.html
new file mode 100644
index 000000000..d0bf094ef
--- /dev/null
+++ b/example/balance.html
@@ -0,0 +1,41 @@
+<!doctype>
+<html>
+
+<head>
+<script type="text/javascript" src="js/es6-promise/promise.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.AutoProvider());
+
+ 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);
+ });
+ });
+ }
+
+</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>
+