-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
87 lines (70 loc) · 3.2 KB
/
index.html
File metadata and controls
87 lines (70 loc) · 3.2 KB
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
81
82
83
84
85
86
87
<!DOCTYPE html>
<head>
<title>Basic Ethereum Dapp</title>
<script src="web3js/dist/web3.min.js" type="text/javascript"></script>
<script type="text/javascript">
var contract_address = "0x98c4b82517F7AD72d9782B271C179b0B7A5fd60E";
var contract_abi = [ { "constant": true, "inputs": [], "name": "getCreator", "outputs": [ { "name": "", "type": "address", "value": "0xb672064863165cebe5460c1e5d5e2cd5bed959fe" } ], "payable": false, "type": "function" }, { "constant": false, "inputs": [], "name": "kill", "outputs": [], "payable": false, "type": "function" }, { "constant": false, "inputs": [ { "name": "myNewNumber", "type": "uint256" } ], "name": "setMyNumber", "outputs": [], "payable": false, "type": "function" }, { "constant": true, "inputs": [], "name": "getNumber", "outputs": [ { "name": "", "type": "uint256", "value": "3" } ], "payable": false, "type": "function" }, { "inputs": [], "payable": false, "type": "constructor" } ];
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://127.0.0.1:8545"));
}
var contract = web3.eth.contract(contract_abi).at(contract_address);
function getCounter() {
contract.getNumber(function (err, result) {
if (!err) {
document.getElementById("myCounter").innerText = result.toNumber();
} else {
console.error(err);
}
});
}
function increaseCounter() {
var currentNumber;
contract.getNumber(function (err, result) {
if (!err) {
currentNumber = result.toNumber();
currentNumber++;
contract.setMyNumber(currentNumber, {
from: web3.eth.accounts[0],
gas: 200000
}, function (err, result) {
if (!err) {
var txHash = result;
console.log(txHash);
} else {
console.error(err);
}
});
} else {
console.error(err);
}
});
}
function getBalance() {
web3.eth.getBalance(web3.eth.accounts[0], function (err, result) {
if (!err) {
document.getElementById("myBalance").innerText = web3.fromWei(result, "ether");
} else {
console.error(err);
}
});
}
</script>
</head>
<body>
<h1>Basic Ethereum Dapp</h1>
<hr>
<h2>Interact with a contract</h2>
<button onclick="getCounter()">Update Counter</button>
<button onclick="increaseCounter()">increaseCounter</button>
<p>Counter is <span id="myCounter"></span></p>
<p id="alert-msg"></p>
<hr>
<h2>This is my balance</h2>
<button onclick="getBalance()">Update my balance</button>
<span id="myBalance"></span> in Ether
</body>
</html>