You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.2 KiB
75 lines
2.2 KiB
10 years ago
|
<!doctype>
|
||
|
<html>
|
||
|
|
||
|
<head>
|
||
10 years ago
|
<script type="text/javascript" src="../dist/web3.js"></script>
|
||
10 years ago
|
<script type="text/javascript">
|
||
|
|
||
|
var web3 = require('web3');
|
||
10 years ago
|
web3.setProvider(new web3.providers.HttpProvider("http://localhost:8545"));
|
||
10 years ago
|
|
||
|
// solidity source code
|
||
10 years ago
|
/*var source = "" +*/
|
||
|
/*"contract test {\n" +*/
|
||
|
/*" function multiply(uint a) constant returns(uint d) {\n" +*/
|
||
|
/*" return a * 7;\n" +*/
|
||
|
/*" }\n" +*/
|
||
|
/*"}\n";*/
|
||
|
var source = "605280600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b60376004356041565b8060005260206000f35b6000600782029050604d565b91905056";
|
||
10 years ago
|
|
||
10 years ago
|
// contract description, this is autogenerated using solc CLI
|
||
|
var desc = [{
|
||
|
"constant" : true,
|
||
|
"inputs" : [{
|
||
|
"name" : "a",
|
||
|
"type" : "uint256"
|
||
|
}],
|
||
|
"name" : "multiply",
|
||
|
"outputs" : [{
|
||
|
"name" : "d",
|
||
|
"type" : "uint256"
|
||
|
}],
|
||
|
"type" : "function"
|
||
10 years ago
|
}];
|
||
|
|
||
10 years ago
|
var myContract;
|
||
10 years ago
|
|
||
|
function createExampleContract() {
|
||
|
// hide create button
|
||
|
document.getElementById('create').style.visibility = 'hidden';
|
||
|
document.getElementById('source').innerText = source;
|
||
|
|
||
10 years ago
|
// let's assume that coinbase is our account
|
||
|
web3.eth.defaultAccount = web3.eth.coinbase;
|
||
10 years ago
|
|
||
10 years ago
|
// create contract
|
||
|
var Contract = web3.eth.contract(desc);
|
||
|
myContract = new Contract({data: source});
|
||
10 years ago
|
document.getElementById('call').style.visibility = 'visible';
|
||
10 years ago
|
}
|
||
|
|
||
|
function callExampleContract() {
|
||
|
// this should be generated by ethereum
|
||
10 years ago
|
var param = parseInt(document.getElementById('value').value);
|
||
10 years ago
|
|
||
|
// call the contract
|
||
10 years ago
|
var res = myContract.multiply(param);
|
||
10 years ago
|
document.getElementById('result').innerText = res.toString(10);
|
||
10 years ago
|
}
|
||
|
|
||
|
</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>
|
||
|
|