-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathindex.html
68 lines (58 loc) · 2.22 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
<html>
<head>
<style type="text/css">
.content {
margin-left: 50%;
margin-top: 50px;
transform: translateX(-50%);
width: 800px;
}
h1 {
text-align: center;
}
input {
font-size: 20px;
margin-bottom: 20px;
text-align: center;
width: 100%;
}
</style>
</head>
<body>
<div class="content">
<h1 id="show-value"></h1>
<input id="input-value" placeholder="new value" type="text" />
<input id="submit-value" type="submit" value="Set Value" />
</div>
<!-- Load the ethers-app library -->
<script src="https://cdn.ethers.io/scripts/ethers-app-v0.5.js" type="text/javascript"></script>
<script type="text/javascript">
// Updates the header content
function updateDisplay(value) {
document.getElementById('show-value').textContent = value;
}
// Load the contract. This JSON file is created by the deploy-contract.js script
app.getContract('simple-store.json').then(function(contract) {
// Get the current value (for initial display)
contract.value().then(function(value) {
updateDisplay(value);
// Set up an event whenever the value changes
contract.onvaluechanged = function(author, oldValue, newValue) {
updateDisplay(newValue);
};
});
// Whenever the user types in a new value...
document.getElementById('submit-value').onclick = function() {
var input = document.getElementById('input-value');
// ... set the value
contract.setValue(input.value).then(function(tx) {
console.log(tx);
input.value = '';
}, function (error) {
console.log(error);
})
};
});
</script>
</body>
</html>