-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb3.html
More file actions
63 lines (58 loc) · 2.3 KB
/
web3.html
File metadata and controls
63 lines (58 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<link rel="stylesheet" type="text/css" href="stylesheets/stylesheet.css" media="screen">
<link rel="stylesheet" type="text/css" href="stylesheets/github-dark.css" media="screen">
<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print">
<title>Web3 client demo</title>
</head>
<body>
<header>
<div class="container" style="padding:20px" id="#container">
</div>
</header>
<script>
var appendText = (id,text) => {
var el = document.getElementById(id)
if(el!=null){
el.innerHTML += ("<br/>"+text)
}
}
var address = "0x3de654b603addf6255a1d88647f703210e389ee6"
appendText('#container',"Address is: "+address)
console.log("connecting to",web3.currentProvider)
web3.version.getNetwork((e,r)=>appendText('#container',"Network is: "+r))
web3.version.getEthereum((e,r)=>appendText("#container","Protocol is: "+r))
try {
console.log("etherbase is",web3.eth.coinbase)
} catch (e) {
console.log("error",e)
}
web3.eth.getBlockNumber((e,r)=>appendText("#container","Block number is: "+r))
web3.eth.getTransactionCount(address,(e,r)=> {
if(e) {
console.log("error gtc",e)
} else {
appendText("#container","Transactions from address: "+r)
}
})
web3.eth.getBlock('latest',(e,r)=>{
if(e) {
console.log(e)
} else {
appendText("#container","Latest Block Hash: "+r.hash)
if(r.transactions.length>0){
appendText("#container","With "+r.transactions.length+" transactions")
r.transactions.forEach((tx)=>{
appendText("#container",tx)
})
} else {
appendText("#container","With no transactions")
}
}
})
</script>
</body>
</html>