2014-11-14 12:11:47 +00:00
|
|
|
<!doctype>
|
|
|
|
<html>
|
|
|
|
|
|
|
|
<head>
|
2015-01-16 15:04:41 +00:00
|
|
|
<script type="text/javascript" src="js/bignumber.js/bignumber.min.js"></script>
|
2014-11-14 12:11:47 +00:00
|
|
|
<script type="text/javascript" src="../dist/ethereum.js"></script>
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
|
|
|
var web3 = require('web3');
|
2015-01-21 20:12:07 +00:00
|
|
|
web3.setProvider(new web3.providers.HttpSyncProvider());
|
2014-11-14 12:11:47 +00:00
|
|
|
|
|
|
|
// solidity source code
|
|
|
|
var source = "" +
|
|
|
|
"contract test {\n" +
|
|
|
|
" function multiply(uint a) returns(uint d) {\n" +
|
|
|
|
" return a * 7;\n" +
|
|
|
|
" }\n" +
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
// contract description, this will be autogenerated somehow
|
|
|
|
var desc = [{
|
2015-01-20 14:06:05 +00:00
|
|
|
"name": "multiply(uint256)",
|
2015-01-29 11:35:21 +00:00
|
|
|
"type": "function",
|
2014-11-14 12:11:47 +00:00
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"name": "a",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"name": "d",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}];
|
|
|
|
|
|
|
|
var contract;
|
|
|
|
|
|
|
|
function createExampleContract() {
|
|
|
|
// hide create button
|
|
|
|
document.getElementById('create').style.visibility = 'hidden';
|
|
|
|
document.getElementById('source').innerText = source;
|
|
|
|
|
|
|
|
// create contract
|
2015-02-19 17:37:09 +00:00
|
|
|
var address = web3.eth.sendTransaction({data: web3.eth.compile.solidity(source)});
|
2015-01-21 20:12:07 +00:00
|
|
|
contract = web3.eth.contract(address, desc);
|
|
|
|
document.getElementById('call').style.visibility = 'visible';
|
2014-11-14 12:11:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function callExampleContract() {
|
|
|
|
// this should be generated by ethereum
|
2015-01-08 14:31:46 +00:00
|
|
|
var param = parseInt(document.getElementById('value').value);
|
2014-11-14 12:11:47 +00:00
|
|
|
|
|
|
|
// call the contract
|
2015-01-27 10:53:34 +00:00
|
|
|
var res = contract.call().multiply(param);
|
|
|
|
document.getElementById('result').innerText = res.toString(10);
|
2014-11-14 12:11:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h1>contract</h1>
|
|
|
|
<div id="source"></div>
|
|
|
|
<div id='create'>
|
|
|
|
<button type="button" onClick="createExampleContract();">create example contract</button>
|
|
|
|
</div>
|
|
|
|
<div id='call' style='visibility: hidden;'>
|
|
|
|
<input type="number" id="value" onkeyup='callExampleContract()'></input>
|
|
|
|
</div>
|
|
|
|
<div id="result"></div>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|