-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
37 lines (32 loc) · 1.48 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
<html>
<head>
<title>Simple Dapp</title>
</head>
<body>
<script src="./web3.min.js"></script>
<script>
var Web3 = require('web3');
var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider("http://localhost:8545"));
var abi = [{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"string"}],"name":"set","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"data","type":"string"}],"payable":false,"type":"function"}];
var contractAddress = "0x64325c9F5FC8EF8E9E2cc62B015C2fdda5a0aB2E";
var helloWorldContract = web3.eth.contract(abi).at(contractAddress);
function get_value_of_x(){
x = helloWorldContract.get();
document.getElementById("value-of-x").innerText = x;
}
function call_contract(){
web3.eth.defaultAccount = web3.eth.accounts[0];
x = document.getElementById("update").value;
helloWorldContract.set(x);
}
</script>
<h1>Simple HTML page</h1>
<h3>Value of x: </h3>
<p id="value-of-x">0</p>
<button onclick="get_value_of_x()">Get value of x</button>
<br>
<input id="update">
<button onclick="call_contract()">Update value</button>
</body>
</html>