updated examples

This commit is contained in:
Marek Kotewicz 2015-05-13 12:05:38 +02:00
parent a0a36e5764
commit 09f2a9200a
2 changed files with 28 additions and 27 deletions

View File

@ -8,14 +8,16 @@
var web3 = require('web3');
web3.setProvider(new web3.providers.HttpProvider("http://localhost:8545"));
// solidity source code
/*var source = "" +*/
/*"contract test {\n" +*/
/*" function multiply(uint a) constant returns(uint d) {\n" +*/
/*" return a * 7;\n" +*/
/*" }\n" +*/
/*"}\n";*/
var source = "605280600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b60376004356041565b8060005260206000f35b6000600782029050604d565b91905056";
// solidity code code
var source = "" +
"contract test {\n" +
" function multiply(uint a) constant returns(uint d) {\n" +
" return a * 7;\n" +
" }\n" +
"}\n";
var code = web3.eth.compile.solidity(source).code;
/*var code = "605280600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b60376004356041565b8060005260206000f35b6000600782029050604d565b91905056";*/
// contract description, this is autogenerated using solc CLI
var desc = [{
@ -37,14 +39,13 @@
function createExampleContract() {
// hide create button
document.getElementById('create').style.visibility = 'hidden';
document.getElementById('source').innerText = source;
document.getElementById('code').innerText = code;
// let's assume that coinbase is our account
web3.eth.defaultAccount = web3.eth.coinbase;
// create contract
var Contract = web3.eth.contract(desc);
myContract = new Contract({data: source});
myContract = web3.eth.contract(desc).new({data: code});
document.getElementById('call').style.visibility = 'visible';
}
@ -61,7 +62,7 @@
</head>
<body>
<h1>contract</h1>
<div id="source"></div>
<div id="code"></div>
<div id='create'>
<button type="button" onClick="createExampleContract();">create example contract</button>
</div>

View File

@ -6,19 +6,20 @@
var web3 = require('web3');
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));
/*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 source = "5b60456000600050819055505b608c8060196000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063371303c014602e57005b6034603a565b60006000f35b6000600081815054600101919050819055506001600260006000505406147f6e61ef44ac2747ff8b84d353a908eb8bd5c3fb118334d57698c5cfc7041196ad600060006000505481526020016000a25b56";
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 code = web3.eth.compile.solidity(source).code;
/*var code = "5b60456000600050819055505b608c8060196000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063371303c014602e57005b6034603a565b60006000f35b6000600081815054600101919050819055506001600260006000505406147f6e61ef44ac2747ff8b84d353a908eb8bd5c3fb118334d57698c5cfc7041196ad600060006000505481526020016000a25b56";*/
var desc = [{
"constant" : false,
@ -51,8 +52,7 @@
var createContract = function () {
// let's assume that we have a private key to coinbase ;)
web3.eth.defaultAccount = web3.eth.coinbase;
var Contract = web3.eth.contract(desc);
contract = new Contract({data: source});
contract = web3.eth.contract(desc).new({data: code});
contract.Incremented({odd: true}).watch(update);
};