-
Notifications
You must be signed in to change notification settings - Fork 0
/
index2.html
80 lines (66 loc) · 2.75 KB
/
index2.html
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- Bootstrap CSS -->
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous"
/>
<title>Document</title>
</head>
<body>
<div style="margin: 50px">
<input type="text" id="input_data" placeholder="BlockNumber / TxHash" />
<button onclick="searchData()">Search</button>
</div>
<table
id="blockTable"
class="table table-dark table-striped"
style="margin: 20px 0 50px 50px; width: 50%"
></table>
</body>
<script type="text/javascript" src="./lib/bignumber.min.js"></script>
<script type="text/javascript" src="./lib/web3.js"></script>
<script type="text/javascript">
// if web3 is not undefined, set new web3 which is web3.currentprovider
if (typeof web3 !== "undefined") {
web3 = new Web3(web3.currentProvider);
} else {
// set the provider you want from Web3.providers
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
if (web3.isConnected()) {
console.log("connected");
} else {
console.log("not connected");
}
function searchData() {
let txHash = document.getElementById("input_data").value;
let blocknumber = document.getElementById("input_data").value;
web3.eth.getTransaction(txHash, function (error, tx) {
let blockData = `<tr> <td> key </td> <td> value </td> </tr>`;
blockData += `<tr> <td> blockNumber </td> <td> ${tx.blockNumber} </td> </tr>
<tr> <td> from </td> <td> ${tx.from} </td> </tr>
<tr> <td> hash </td> <td> ${tx.hash} </td> </tr>
<tr> <td> nonce </td> <td> ${tx.nonce} </td> </tr>
<tr> <td> to </td> <td> ${tx.to} </td> </tr>`;
document.getElementById("blockTable").innerHTML = blockData;
});
web3.eth.getBlock(blocknumber, function (error, block) {
let blockData = `<tr> <td> key </td> <td> value </td> </tr>`;
blockData += `<tr> <td> blockNumber </td> <td> ${block.blockNumber} </td> </tr>
<tr> <td> from </td> <td> ${block.from} </td> </tr>
<tr> <td> hash </td> <td> ${block.hash} </td> </tr>
<tr> <td> nonce </td> <td> ${block.nonce} </td> </tr>
<tr> <td> to </td> <td> ${block.to} </td> </tr>`;
document.getElementById("blockTable").innerHTML = blockData;
});
}
searchData();
</script>
</html>