diff options
author | Marek Kotewicz <marek.kotewicz@gmail.com> | 2014-11-14 02:28:58 +0800 |
---|---|---|
committer | Marek Kotewicz <marek.kotewicz@gmail.com> | 2014-11-14 02:28:58 +0800 |
commit | 8aaec1d98fdeef1521e65518913498a1a0c18cbe (patch) | |
tree | 504894cb720802862679c934f57fcfa93af5bd13 /example | |
parent | b1428555d10c5449e0f91f53f1dd0e8d1a1f9732 (diff) | |
download | dexon-8aaec1d98fdeef1521e65518913498a1a0c18cbe.tar.gz dexon-8aaec1d98fdeef1521e65518913498a1a0c18cbe.tar.zst dexon-8aaec1d98fdeef1521e65518913498a1a0c18cbe.zip |
improved example
Diffstat (limited to 'example')
-rw-r--r-- | example/index.html | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/example/index.html b/example/index.html index dc507ec9c..4847f68c0 100644 --- a/example/index.html +++ b/example/index.html @@ -4,34 +4,38 @@ <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"> - if (window.Promise === undefined) { - window.Promise = ES6Promise.Promise; - } - + var web3 = require('web3'); web3.setProvider(new web3.providers.AutoProvider()); - function testSnippet() { - web3.eth.watch({altered: web3.eth.coinbase}).changed(function() { - web3.eth.balanceAt(web3.eth.coinbase).then(function (balance) { - console.log(parseInt(balance,16)); - console.log(typeof balance); - document.getElementById("result").innerText = +balance; + 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> +</script> +</head> <body> - <h1>std::name_reg</h1> - <input type="text" id="name"></input> - <button type="button" onClick="testSnippet();">test snippet</button> + <h1>balance</h1> + <button type="button" onClick="watchBalance();">watch balance</button> <div></div> - result: - <div id="result"></div> + <div id="original"></div> + <div id="current"></div> + <div id="diff"></div> </body> </html> |