mirror of
https://github.com/status-im/web3.js.git
synced 2025-02-23 19:48:13 +00:00
fixed #133
This commit is contained in:
parent
55553d78dd
commit
69e7d9d015
@ -49,7 +49,7 @@
|
||||
// create contract
|
||||
myContract = web3.eth.contract(desc).new({data: code});
|
||||
console.log('address: ' + myContract.address);
|
||||
document.getElementById('status').innerText = "transaction send, waiting for confirmation";
|
||||
document.getElementById('status').innerText = "transaction sent, waiting for confirmation";
|
||||
watch.watch(function (err, hash) {
|
||||
var block = web3.eth.getBlock(hash, true);
|
||||
var contractMined = block.transactions.reduce(function (mined, th) {
|
||||
|
@ -10,7 +10,7 @@
|
||||
"contract Contract { " +
|
||||
" event Incremented(bool indexed odd, uint x); " +
|
||||
" function Contract() { " +
|
||||
" x = 69; " +
|
||||
" x = 70; " +
|
||||
" } " +
|
||||
" function inc() { " +
|
||||
" ++x; " +
|
||||
@ -52,12 +52,40 @@
|
||||
var createContract = function () {
|
||||
// let's assume that we have a private key to coinbase ;)
|
||||
web3.eth.defaultAccount = web3.eth.coinbase;
|
||||
|
||||
var watch = web3.eth.filter('latest');
|
||||
|
||||
contract = web3.eth.contract(desc).new({data: code});
|
||||
|
||||
console.log('address: ' + contract.address);
|
||||
|
||||
document.getElementById('create').style.visibility = 'hidden';
|
||||
document.getElementById('status').innerText = "transaction sent, waiting for confirmation";
|
||||
watch.watch(function (err, hash) {
|
||||
var block = web3.eth.getBlock(hash, true);
|
||||
var contractMined = block.transactions.reduce(function (mined, th) {
|
||||
// TODO: compiled code do not have 0x prefix
|
||||
return mined || (th.from === web3.eth.defaultAccount && th.input.indexOf(code) !== -1);
|
||||
}, false);
|
||||
|
||||
if (contractMined) {
|
||||
document.getElementById('status').innerText = 'Mined!';
|
||||
document.getElementById('call').style.visibility = 'visible';
|
||||
}
|
||||
});
|
||||
|
||||
contract.Incremented({odd: true}).watch(update);
|
||||
|
||||
};
|
||||
|
||||
var counter = 0;
|
||||
var callContract = function () {
|
||||
counter++;
|
||||
var all = 70 + counter;
|
||||
document.getElementById('count').innerText = 'Transaction sent ' + counter + ' times. ' +
|
||||
'Expected x value is: ' + (all - (all % 2 ? 0 : 1)) + ' ' +
|
||||
'Waiting for the blocks to be mined...';
|
||||
|
||||
contract.inc();
|
||||
};
|
||||
|
||||
@ -66,12 +94,14 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="status"></div>
|
||||
<div>
|
||||
<button type="button" onClick="createContract();">create contract</button>
|
||||
<button id="create" type="button" onClick="createContract();">create contract</button>
|
||||
</div>
|
||||
<div>
|
||||
<button type="button" onClick="callContract();">test1</button>
|
||||
<button id="call" style="visibility: hidden;" type="button" onClick="callContract();">test1</button>
|
||||
</div>
|
||||
<div id='count'></div>
|
||||
<div id="result">
|
||||
</div>
|
||||
</body>
|
||||
|
Loading…
x
Reference in New Issue
Block a user