-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
69 lines (53 loc) · 2.38 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="web3.min.js"></script>
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="js/bootstrap.min.js"></script>
<title>Ethereum Simple Storage Example</title>
</head>
<body>
<div class="container">
<div class="jumbotron">
<div>
<h3>Store a Value in the blockchain</h3>
<input type="text" placeholder="value to set" id="myValue"> </input> <button class="btn btn btn-primary" onclick="setValue()">Go!</button>
</div>
<div>
<h3>Retrieve that Value</h3>
<button onclick="getValue()" class="btn btn- btn-info">Get Value</button><br>
<div style="font-size: 18px; color: red" id="result" class="textbox">
</div>
</div>
</div> <!-- End Container -->
<!-- http://159.203.57.99:8545")); -->
<script>
// set current provider
if(typeof window.web3 !== "undefined" && typeof window.web3.currentProvider !== "undefined") {
var web3 = new Web3(window.web3.currentProvider);
} else {
var web3 = new Web3(new Web3.providers.HttpProvider("http://10.0.3.174:8545"));
}
simplestorageContract = web3.eth.contract([{"constant":true,"inputs":[],"name":"getValue","outputs":[{"name":"","type":"string"}],"type":"function"},{"constant":false,"inputs":[{"name":"value","type":"string"}],"name":"setValue","outputs":[],"type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"oldValue","type":"string"},{"indexed":false,"name":"newValue","type":"string"}],"name":"valueChanged","type":"event"}]);
Address = "0x5DFbf7fFCF4D1ec5dcB1Aa0262C0a72f981F045d"
function setValue() {
var val = document.getElementById('myValue').value;
var Transaction = simplestorageContract.at(Address);
var TxHash = Transaction["setValue"].sendTransaction(val, {from: web3.eth.accounts[0]}, function(err, address) {
console.log(address);
})
}
function getValue() {
var p = simplestorageContract.at(Address);
var returnValue = p.getValue().toString();
console.log(returnValue);
document.getElementById("result").innerHTML=returnValue;
}
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="js/jquery.min.js"></script>
</body>
</html>