Official Go implementation of the Ethereum protocol
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-ethereum/example/index.html

42 lines
1.3 KiB

10 years ago
<!doctype>
<html>
<head>
<script type="text/javascript" src="js/es6-promise/promise.min.js"></script>
<script type="text/javascript" src="../dist/ethereum.js"></script>
10 years ago
<script type="text/javascript">
10 years ago
var web3 = require('web3');
web3.setProvider(new web3.providers.AutoProvider());
10 years ago
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);
});
10 years ago
});
}
10 years ago
10 years ago
</script>
</head>
10 years ago
<body>
10 years ago
<h1>balance</h1>
<button type="button" onClick="watchBalance();">watch balance</button>
<div></div>
10 years ago
<div id="original"></div>
<div id="current"></div>
<div id="diff"></div>
10 years ago
</body>
</html>