Skip to content

Instantly share code, notes, and snippets.

@pau1m
Last active September 9, 2017 13:53
Show Gist options
  • Save pau1m/4a3550689bb072ae937266e366755d20 to your computer and use it in GitHub Desktop.
Save pau1m/4a3550689bb072ae937266e366755d20 to your computer and use it in GitHub Desktop.
web 3 find transaction in 12th block
let filter = web3.eth.filter('latest')
filter.watch(function(error, result){
if (!error) {
let confirmedBlockId = web3.eth.blockNumber - 12
web3.eth.getBlock(confirmedBlockId, function(error, res){
if (!error) {
if (res.transactions.length > 0) {
res.transactions.forEach(function(txId){
web3.eth.getTransaction(txId, function(error, tx) {
if (!error && tx.to == account) {
console.log('tx in 12th block from: ' + tx.from)
}
})
})
}
}
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment