forked from mempirate/eth-transaction-checker
-
Notifications
You must be signed in to change notification settings - Fork 2
/
transactionChecker2.js
26 lines (24 loc) · 989 Bytes
/
transactionChecker2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
'use strict';
module.exports = ({ web3, web3http }) => {
const account = 'YOUR_ETH_ADDRESS'.toLowerCase();
const subscription = web3.eth.subscribe('pendingTransactions', (err, res) => {
if (err) console.error(err);
});
return function watchTransactions() {
console.log('[+] Watching transactions...');
subscription.on('data', (txHash) => {
setTimeout(async () => {
try {
let tx = await web3http.eth.getTransaction(txHash);
if (tx.to) {
if (tx.to.toLowerCase() === account) {
console.log({ address: tx.from, value: web3.utils.fromWei(tx.value, 'ether'), timestamp: new Date() });
}
}
} catch (err) {
console.error(err);
}
}, 60 * 1000);
});
}
}