-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpendingTxWatcher.js
26 lines (23 loc) · 1.06 KB
/
pendingTxWatcher.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
const Web3 = require('web3');
let provider = new Web3.providers.WebsocketProvider('wss://rinkeby.infura.io/ws/v3/YOUR INFURA KEY');
let web3 = new Web3(provider);
const account = 'INSERT CONTRACT ADDRESS'.toLowerCase();
const subscription = web3.eth.subscribe('pendingTransactions', (err, res) => {
if (err) console.error(err);
});
subscription.on('data', (txHash) => {
setTimeout(async () => {
try {
let tx = await web3.eth.getTransaction(txHash);
if (tx && tx.from && tx.from.toLowerCase() === account) {
console.log('Transaction Hash: ',txHash );
console.log('Transaction Confirmation Index: ',tx.transactionIndex );// 0 when transaction is pending
console.log('Transaction Received from: ',tx.from );
console.log('Transaction Amount(in Ether): ',web3.utils.fromWei(tx.value, 'ether'));
console.log('Transaction Receiving Date/Time: ',new Date());
}
} catch (err) {
console.error(err);
}
}, 15 * 1000); // running at 15 seconds
});