updated examples

This commit is contained in:
Marek Kotewicz 2015-07-07 11:51:13 +02:00
parent 368b1b56aa
commit 84a3d93c54
4 changed files with 52 additions and 45 deletions

View File

@ -16,7 +16,7 @@
document.getElementById('coinbase').innerText = 'coinbase: ' + coinbase;
document.getElementById('original').innerText = ' original balance: ' + originalBalance + ' watching...';
web3.eth.filter('pending').watch(function() {
web3.eth.filter('latest').watch(function() {
var currentBalance = web3.eth.getBalance(coinbase).toNumber();
document.getElementById("current").innerText = 'current: ' + currentBalance;
document.getElementById("diff").innerText = 'diff: ' + (currentBalance - originalBalance);

View File

@ -34,7 +34,12 @@
var watch = web3.eth.filter('latest');
// create contract
myContract = web3.eth.contract(abi).new({data: code});
web3.eth.contract(abi).new({data: code}, function (err, contract) {
if (err) {
console.error('contract creation failed!');
return;
}
myContract = contract;
console.log('address: ' + myContract.address);
document.getElementById('status').innerText = "transaction sent, waiting for confirmation";
watch.watch(function (err, hash) {
@ -49,7 +54,7 @@
document.getElementById('call').style.visibility = 'visible';
}
});
});
}
function callExampleContract() {

View File

@ -34,7 +34,12 @@
var watch = web3.eth.filter('latest');
// create contract
myContract = web3.eth.contract(abi).new({data: code});
web3.eth.contract(abi).new({data: code}, function (err, contract) {
if (err) {
console.error('contract creation failed!');
return;
}
myContract = contract;
console.log('address: ' + myContract.address);
document.getElementById('status').innerText = "transaction sent, waiting for confirmation";
watch.watch(function (err, hash) {
@ -49,7 +54,7 @@
document.getElementById('call').style.visibility = 'visible';
}
});
});
}
function callExampleContract() {

View File

@ -37,27 +37,24 @@
var watch = web3.eth.filter('latest');
contract = web3.eth.contract(abi).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) {
web3.eth.contract(abi).new({data: code}, function (err, c) {
if (err) {
console.error('contract creation failed!');
return;
}
contract = c;
console.log('address: ' + contract.address);
document.getElementById('status').innerText = 'Mined!';
document.getElementById('call').style.visibility = 'visible';
}
});
inc = contract.Incremented({odd: true});
inc.watch(update);
});
};
var counter = 0;