-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocbackup.html
70 lines (61 loc) · 3.01 KB
/
docbackup.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
<!doctype html>
<html>
<head>
<title>
myDapp
</title>
<script src="web3.js/dist/web3.min.js"></script>
<script type="text/javascript">
var contract_address = "0xB08E852e9AC42cB733B5D862F5a2dd545b960A01";
var contract_abi = [ { "constant": true, "inputs": [], "name": "getCreator", "outputs": [ { "name": "", "type": "address", "value": "0xd1a5cafa7098f7b74e8369810ba2dfc1cd67d9db" } ], "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": "getMyNumber", "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://localhost:8545"));
}
var contract_instance = web3.eth.contract(contract_abi).at(contract_address);
function getCounter() {
document.getElementById("myCounter").innerText = contract_instance.getMyNumber().toNumber();
}
function increaseCounter() {
var currentNumber = contract_instance.getMyNumber().toNumber();
currentNumber++;
web3.personal.unlockAccount(web3.eth.accounts[0], 'test1234');
contract_instance.setMyNumber(currentNumber, {from: web3.eth.accounts[0]}, function(error, result) {
if(error) {
console.error(error);
} else {
var txHash = result;
console.log(txHash);
callWhenMined(txHash, getCounter);
}
});
}
function callWhenMined(txHash, callback) {
web3.eth.getTransactionReceipt(txHash, function(error, rcpt) {
if(error) {
console.error(error);
} else {
if(rcpt == null) {
setTimeout(function() {
callWhenMined(txHash, callback);
}, 500);
} else {
callback();
}
}
})
}
function getBalance(){
document.getElementById("myBalance").innerText = web3.fromWei(web3.eth.getBalance(web3.eth.accounts[0]), "ether");
}
</script>
</head>
<body>
<h1>Interact with a contract</h1>
<button onclick="getCounter()">Update Counter</button>
<button onclick="increaseCounter()">Increase Counter</button>
<span id="myCounter"></span> Counter
</body>
</html>