forked from ledgerlabs/ether.storage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
old.html
68 lines (56 loc) · 3.71 KB
/
old.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="web3.min.js"></script>
<title></title>
</head>
<body>
<div>
Click da' button to deploy contract
<button onclick="deploy()">Deploy!</button>
</div>
<div>
<input type="text" placeholder="value to set" id="myValue"> </input> <button onclick="setValue()">Go!</button>
</div>
<div>
<button onclick="getValue()">Get Value</button><br>
<div id="result">
</div>
</div>
<script>
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
function deploy() {
console.log(web3.isConnected())
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"}]);
var simplestorage = simplestorageContract.new(
{
from: web3.eth.accounts[0],
data: '6060604052610317806100126000396000f3606060405260e060020a600035046320965255811461002657806393a0935214610089575b005b610141600060608181528154602060026001831615610100026000190190921691909104601f810182900490910260a0908101604052608082815292939190828280156101da5780601f106101af576101008083540402835291602001916101da565b60206004803580820135601f81018490049093026080908101604052606084815261002494602493919291840191819083828082843750506040805181815260008054600260018216156101000260001901909116049282018390529698507f68ad6719a0070b3bb2f866fa0d46c8123b18cefe9b387ddb4feb6647ca41843597508895509350839250602083019150828501908690801561020f5780601f106101e45761010080835404028352916020019161020f565b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156101a15780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b820191906000526020600020905b8154815290600101906020018083116101bd57829003601f168201915b5050505050905090565b820191906000526020600020905b8154815290600101906020018083116101f257829003601f168201915b50508381038252848181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156102695780820380516001836020036101000a031916815260200191505b5094505050505060405180910390a18060006000509080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106102de57805160ff19168380011785555b5061030e9291505b80821115610313578381556001016102cb565b828001600101855582156102c3579182015b828111156102c35782518260005055916020019190600101906102f0565b505050565b509056',
gas: 4700000
}, function (e, contract){
console.log(e, contract);
if (typeof contract.address !== 'undefined') {
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
Address = contract.address;
}
})
}
function setValue() {
var val = document.getElementById('myValue').value;
var contractAbi = web3.eth.contract(simplestorageContract);
var Transaction = contractAbi.at(Address);
var TxHash = Transaction["setValue"].sendTransaction(val, {from: web3.eth.accounts[0]}, function(err, address) {
console.log(address);
})
}
function getValue() {
var contractAbi = web3.eth.contract(simplestorageContract);
var p = contractAbi.at(Address);
var returnValue = p.getValue().toString();
console.log(returnValue);
document.getElementById("result").innerHTML=returnValue;
}
</script>
</body>
</html>