My goal here is to list all transaction from an given account, without any success yet.
I wonder why I always have an empty result when I'm using this web3.eth.filter
. I know there is a valid solution: Listing transactions in a private blockchain, but going through all blocks each time takes a considerable amount of time, so it is not really responsive on the user side.
So I wonder what is wrong with my code:
web3.eth.defaultAccount = web3.eth.accounts[0];
var account = web3.eth.accounts[0];
console.log('Account: '+ account);
var filter = web3.eth.filter({fromBlock:0, toBlock: 'latest', address: account});
filter.get(function(error, result) {
if(!error) {
for (i=0; i<result.length; ++i) {
var block = web3.eth.getBlock(i, true);
block.transactions.forEach( function(e) {
console.log(" tx hash : " + e.hash + "\n"
+ " nonce : " + e.nonce + "\n"
+ " blockHash : " + e.blockHash + "\n"
+ " blockNumber : " + e.blockNumber + "\n"
+ " transactionIndex: " + e.transactionIndex + "\n"
+ " from : " + e.from + "\n"
+ " to : " + e.to + "\n"
+ " value : " + e.value + "\n"
+ " time : " + block.timestamp + " " + new Date(block.timestamp * 1000).toGMTString() + "\n"
+ " gasPrice : " + e.gasPrice + "\n"
+ " gas : " + e.gas + "\n"
+ " input : " + web3.toAscii(e.input))+"\n";
})
}
}
else {
console.log('Error: '+error);
}
});
I also tried with filter.watch
, but the results remains the same: results is still empty.
Thanks