Created
April 8, 2015 13:41
-
-
Save czepluch/724aa76daffa6478cd00 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>JavaScript API</title> | |
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> | |
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"> | |
<script type="text/javascript" src="~/cpp-ethereum/libjsqrc/ethereumjs/dist/ethereum.js"></script> | |
<script type="text/javascript"> | |
///First web3.eth.watch code to monitor coinbase | |
setTimeout(function() { | |
///var web3 = require('ethereum.js'); | |
///Insert your contract address var here: | |
var contractAddress = "0xe16ebba850103f86741885e2e9d70d04e10508df"; | |
///Second web3.eth.watch code to monitor block number | |
web3.eth.filter('latest').watch(function(){ | |
var coinbase = web3.eth.coinbase; | |
document.getElementById('coinbase').innerText = coinbase; | |
var balance = web3.eth.getBalance(coinbase); | |
document.getElementById('balance').innerText = web3.toDecimal(balance); | |
}); | |
web3.eth.filter('pending').watch(function() { | |
var blockNumber = web3.eth.blockNumber; | |
document.getElementById('latestBlock').innerText = blockNumber; | |
var hash = web3.eth.getBlock(blockNumber).hash; | |
document.getElementById('latestBlockHash').innerText = hash; | |
var timeStamp = web3.eth.getBlock(blockNumber).timestamp; | |
document.getElementById('latestBlockTimestamp').innerText = Date(timeStamp); | |
var contractString = JSON.stringify(web3.eth.getStorageAt(contractAddress, 2)); | |
document.getElementById('contractString').innerText = web3.toAscii(contractString); | |
var firstName = web3.eth.getStorageAt(contractAddress, 0); | |
var lastName = web3.eth.getStorageAt(contractAddress, 1); | |
document.getElementById('fullName').innerText = web3.toAscii(firstName) + ' ' + web3.toAscii(lastName); | |
});},5000); | |
</script> | |
</head> | |
<body> | |
<div class="header"> | |
<h3>JavaScript API</h3> | |
</div> | |
<div class="jumbotron"> | |
<h5>Coinbase Address: <strong id="coinbase"></strong></h5> | |
<h5>Balance: <strong id="balance"></strong></h5> | |
<h5>Latest Block Number: <strong id="latestBlock"></strong></h5> | |
<h5>Latest Block Timestamp: <strong id="latestBlockTimestamp"></strong></h5> | |
<h5>Latest Block Hash: <strong id="latestBlockHash"></strong></h5> | |
<h5>Contract String: <strong id="contractString"></strong></h5> | |
<h5>Full name: <strong id="fullName"></strong></h5> | |
<br> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment