2015-02-02 10:52:56 +00:00
|
|
|
<!doctype>
|
|
|
|
<html>
|
|
|
|
<head>
|
2015-04-07 02:39:47 +00:00
|
|
|
<script type="text/javascript" src="../dist/web3.js"></script>
|
2015-02-02 10:52:56 +00:00
|
|
|
<script type="text/javascript">
|
2015-04-07 02:39:47 +00:00
|
|
|
var web3 = require('web3');
|
2015-03-10 12:27:16 +00:00
|
|
|
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8080'));
|
2015-02-02 10:52:56 +00:00
|
|
|
|
|
|
|
var source = "" +
|
|
|
|
"contract Contract { " +
|
|
|
|
" event Incremented(bool indexed odd, uint x); " +
|
|
|
|
" function Contract() { " +
|
|
|
|
" x = 69; " +
|
|
|
|
" } " +
|
|
|
|
" function inc() { " +
|
|
|
|
" ++x; " +
|
|
|
|
" Incremented(x % 2 == 1, x); " +
|
|
|
|
" } " +
|
|
|
|
" uint x; " +
|
|
|
|
"}";
|
|
|
|
|
|
|
|
var desc = [{
|
|
|
|
"type":"event",
|
|
|
|
"name":"Incremented",
|
|
|
|
"inputs": [{"name":"odd","type":"bool","indexed":true},{"name":"x","type":"uint","indexed":false}],
|
|
|
|
}, {
|
|
|
|
"type":"function",
|
|
|
|
"name":"inc",
|
|
|
|
"inputs": [],
|
|
|
|
"outputs": []
|
|
|
|
}];
|
|
|
|
|
|
|
|
var address;
|
|
|
|
var contract;
|
|
|
|
|
|
|
|
var update = function (x) {
|
|
|
|
document.getElementById('result').innerText = JSON.stringify(x);
|
|
|
|
};
|
|
|
|
|
|
|
|
var createContract = function () {
|
2015-02-19 17:37:09 +00:00
|
|
|
address = web3.eth.sendTransaction({data: web3.eth.compile.solidity(source)});
|
2015-02-02 10:52:56 +00:00
|
|
|
contract = web3.eth.contract(address, desc);
|
|
|
|
contract.Incremented({odd: true}).changed(update);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
var callContract = function () {
|
|
|
|
contract.call().inc();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
<div>
|
|
|
|
<button type="button" onClick="createContract();">create contract</button>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<button type="button" onClick="callContract();">test1</button>
|
|
|
|
</div>
|
|
|
|
<div id="result">
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|