-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
76 lines (60 loc) · 2.54 KB
/
index.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
<html>
<head>
<title>Simple ledger</title>
<style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
margin: 60px auto;
max-width: 320px;
padding: 0em 1em;
}
ul {
list-style-type: none;
padding: 0em 1em;
}
li {
display: block;
margin: 10px;
}
h1 {
text-align: center;
font-size: 2em;
}
p {
color: gray;
font-size: 0.8em;
text-align: center;
}
</style>
</head>
<body>
<div id="app">
<h1>Simple ledger</h1>
<div id="entity_list">
<ul></ul>
</div>
<p>Open developer tools and view console for logging</p>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script src="https://cdn.ethers.io/scripts/ethers-v2.0.min.js" type="text/javascript"></script>
<script>
var provider = new ethers.providers.InfuraProvider('ropsten');
var address = '0x0C3dc5ec9106CF7c5702430e727De76786fb3C9e';
var abi = '[{"constant":false,"inputs":[{"name":"_entity","type":"bytes2"},{"name":"_amount","type":"int256"}],"name":"recordEntry","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"","type":"bytes2"}],"name":"ledger","outputs":[{"name":"","type":"int256"}],"payable":false,"type":"function"},{"inputs":[],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_entity","type":"bytes2"},{"indexed":false,"name":"_amount","type":"int256"}],"name":"SimpleLedgerEntry","type":"event"}]';
console.log('Instantiating contract at ' + address);
console.log('Contract ABI ' + abi);
var contract = new ethers.Contract(address, abi, provider);
console.log(contract);
contract.owner().then(function (result) {
console.log('Owner ' + result[0]);
});
// we expect possible entries for these entities; 0 returned if no entry
['AG', 'EE', 'KG', 'JM'].forEach(function (entity) {
contract.ledger(ethers.utils.toUtf8Bytes(entity)).then(function (result) {
console.log(entity + ': ' + result[0].toString());
$('#entity_list ul').append('<li>' + entity + ': <strong>' + result[0].toString() + '</strong></li>');
});
});
</script>
</body>
</html>