mirror of
https://github.com/status-im/web3.js.git
synced 2025-02-24 03:58:13 +00:00
updated examples
This commit is contained in:
parent
368b1b56aa
commit
84a3d93c54
@ -16,7 +16,7 @@
|
|||||||
document.getElementById('coinbase').innerText = 'coinbase: ' + coinbase;
|
document.getElementById('coinbase').innerText = 'coinbase: ' + coinbase;
|
||||||
document.getElementById('original').innerText = ' original balance: ' + originalBalance + ' watching...';
|
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();
|
var currentBalance = web3.eth.getBalance(coinbase).toNumber();
|
||||||
document.getElementById("current").innerText = 'current: ' + currentBalance;
|
document.getElementById("current").innerText = 'current: ' + currentBalance;
|
||||||
document.getElementById("diff").innerText = 'diff: ' + (currentBalance - originalBalance);
|
document.getElementById("diff").innerText = 'diff: ' + (currentBalance - originalBalance);
|
||||||
|
@ -34,7 +34,12 @@
|
|||||||
var watch = web3.eth.filter('latest');
|
var watch = web3.eth.filter('latest');
|
||||||
|
|
||||||
// create contract
|
// 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);
|
console.log('address: ' + myContract.address);
|
||||||
document.getElementById('status').innerText = "transaction sent, waiting for confirmation";
|
document.getElementById('status').innerText = "transaction sent, waiting for confirmation";
|
||||||
watch.watch(function (err, hash) {
|
watch.watch(function (err, hash) {
|
||||||
@ -49,7 +54,7 @@
|
|||||||
document.getElementById('call').style.visibility = 'visible';
|
document.getElementById('call').style.visibility = 'visible';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function callExampleContract() {
|
function callExampleContract() {
|
||||||
|
@ -34,7 +34,12 @@
|
|||||||
var watch = web3.eth.filter('latest');
|
var watch = web3.eth.filter('latest');
|
||||||
|
|
||||||
// create contract
|
// 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);
|
console.log('address: ' + myContract.address);
|
||||||
document.getElementById('status').innerText = "transaction sent, waiting for confirmation";
|
document.getElementById('status').innerText = "transaction sent, waiting for confirmation";
|
||||||
watch.watch(function (err, hash) {
|
watch.watch(function (err, hash) {
|
||||||
@ -49,7 +54,7 @@
|
|||||||
document.getElementById('call').style.visibility = 'visible';
|
document.getElementById('call').style.visibility = 'visible';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function callExampleContract() {
|
function callExampleContract() {
|
||||||
|
@ -37,27 +37,24 @@
|
|||||||
|
|
||||||
var watch = web3.eth.filter('latest');
|
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('create').style.visibility = 'hidden';
|
||||||
document.getElementById('status').innerText = "transaction sent, 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) {
|
|
||||||
// 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('status').innerText = 'Mined!';
|
||||||
document.getElementById('call').style.visibility = 'visible';
|
document.getElementById('call').style.visibility = 'visible';
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
inc = contract.Incremented({odd: true});
|
inc = contract.Incremented({odd: true});
|
||||||
inc.watch(update);
|
inc.watch(update);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var counter = 0;
|
var counter = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user