2015-01-28 09:58:43 +00:00
|
|
|
<!doctype>
|
|
|
|
<html>
|
|
|
|
|
|
|
|
<head>
|
2015-01-28 13:02:36 +00:00
|
|
|
<script type="text/javascript" src="../bignumber.min.js"></script>
|
2015-01-28 09:58:43 +00:00
|
|
|
<script type="text/javascript" src="../dist/ethereum.js"></script>
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
2015-01-28 13:02:36 +00:00
|
|
|
console.log("hello world");
|
2015-01-28 09:58:43 +00:00
|
|
|
var web3 = require('web3');
|
2015-01-28 13:02:36 +00:00
|
|
|
console.log(web3)
|
2015-01-28 09:58:43 +00:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-01-28 13:02:36 +00:00
|
|
|
var request = new XMLHttpRequest();
|
|
|
|
request.open('POST', "http://localhost:8080", false);
|
|
|
|
request.send({});
|
|
|
|
|
|
|
|
|
2015-01-28 09:58:43 +00:00
|
|
|
</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>
|
|
|
|
|