From 09f2a9200a550a55bc521b0f25954a15746cc905 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Wed, 13 May 2015 12:05:38 +0200 Subject: [PATCH] updated examples --- example/contract.html | 25 +++++++++++++------------ example/event_inc.html | 30 +++++++++++++++--------------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/example/contract.html b/example/contract.html index a320985..3de9eb6 100644 --- a/example/contract.html +++ b/example/contract.html @@ -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 @@

contract

-
+
diff --git a/example/event_inc.html b/example/event_inc.html index ac12c64..d33a3f1 100644 --- a/example/event_inc.html +++ b/example/event_inc.html @@ -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); };