2015-01-13 16:59:42 +02:00
|
|
|
<!doctype>
|
|
|
|
<html>
|
|
|
|
|
|
|
|
<head>
|
|
|
|
<script type="text/javascript" src="js/es6-promise/promise.min.js"></script>
|
|
|
|
<script type="text/javascript" src="../dist/ethereum.js"></script>
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
|
|
|
var web3 = require('web3');
|
|
|
|
web3.setProvider(new web3.providers.AutoProvider());
|
|
|
|
|
|
|
|
// solidity source code
|
|
|
|
var source = "" +
|
|
|
|
"contract test {\n" +
|
2015-01-13 18:54:09 +02:00
|
|
|
" /// @notice Will multiplty `a` by 7. \n" +
|
2015-01-13 16:59:42 +02:00
|
|
|
" function multiply(uint a) returns(uint d) {\n" +
|
|
|
|
" return a * 7;\n" +
|
|
|
|
" }\n" +
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
// contract description, this will be autogenerated somehow
|
|
|
|
var desc = [{
|
|
|
|
"name": "multiply",
|
|
|
|
"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
|
|
|
|
web3.eth.transact({code: web3.eth.solidity(source)}).then(function (address) {
|
|
|
|
contract = web3.contract(address, desc);
|
|
|
|
document.getElementById('call').style.visibility = 'visible';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function callExampleContract() {
|
|
|
|
// this should be generated by ethereum
|
|
|
|
var param = parseInt(document.getElementById('value').value);
|
|
|
|
|
|
|
|
// call the contract
|
|
|
|
contract.multiply(param).transact().then(function(res) {
|
|
|
|
document.getElementById('result').innerText = res[0];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
</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>
|
|
|
|
|