I wrote some simple code with web3js to track an address/account's transaction in real-time. It works, but I think it is in poor performance or could consume too much cpu resources.
sample code
let filter = web3.eth.filter("latest");
filter.watch(function(error, result) {
if (!error) {
//tracking start in 12 blocks earlier .
var earlierNumber = web3.eth.getBlock(result).number - 12;
var confirmedBlock = web3.eth.getBlock(earlierNumber ) ;
if (confirmedBlock.transactions.length > 0) {
confirmedBlock.transactions.forEach(function(tx) {
if ( tx.to == address ) {
var depositAmount = web3.fromWei(tx.value.toNumber(),
"ether" )
console.log("address: " +address+ " deposit amount: "+depositAmount+ " ETH." ) ;
}
})
}
}
})
How could those large scale trade or exchange platform track huge amount of account' transaction accurately ? I find much good project such as MetaMask-token-tracker ,on Git. How about it? Or any open source to recommend?