Skip to content

Commit f2173f8

Browse files
author
Jonas Bostoen
committed
Added placeholders
1 parent 601aaee commit f2173f8

File tree

3 files changed

+25
-27
lines changed

3 files changed

+25
-27
lines changed

ethClient.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
'use strict'
1+
'use strict';
22

33
module.exports = Web3 => ({
4-
web3http: new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/v3/0e4e7262741e4db18a020768e66f018e')),
5-
web3: new Web3(new Web3.providers.WebsocketProvider('wss://rinkeby.infura.io/ws/v3/0e4e7262741e4db18a020768e66f018e'))
4+
web3http: new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/v3/YOUR_INFURA_API_KEY')),
5+
web3: new Web3(new Web3.providers.WebsocketProvider('wss://rinkeby.infura.io/ws/v3/YOUR_INFURA_API_KEY'))
66
})

transactionChecker.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
'use strict'
1+
'use strict';
22

33
module.exports = web3 => {
4-
const account = '0xe1Dd30fecAb8a63105F2C035B084BfC6Ca5B1493'.toLowerCase()
4+
const account = 'YOUR_ETH_ADDRESS'.toLowerCase();
55

66
return {
77
checkLastBlock: async () => {
8-
let block = await web3.eth.getBlock('latest')
9-
console.log(`[*] Searching block ${ block.number }...`)
8+
let block = await web3.eth.getBlock('latest');
9+
console.log(`[*] Searching block ${ block.number }...`);
1010
if (block && block.transactions) {
1111
for (let tx of block.transactions) {
12-
let transaction = await web3.eth.getTransaction(tx)
12+
let transaction = await web3.eth.getTransaction(tx);
1313
if (account === transaction.to.toLowerCase()) {
14-
console.log(`[+] Transaction found on block ${ lastBlockNumber }`)
15-
console.log({ address: transaction.from, value: web3.utils.fromWei(transaction.value, 'ether'), timestamp: new Date() })
14+
console.log(`[+] Transaction found on block ${ lastBlockNumber }`);
15+
console.log({ address: transaction.from, value: web3.utils.fromWei(transaction.value, 'ether'), timestamp: new Date() });
1616
}
1717
}
1818
}
@@ -21,14 +21,13 @@ module.exports = web3 => {
2121
checkBlocks: async (start, end) => {
2222
for (let i = start; i < end; i++) {
2323
let block = await web3.eth.getBlock(i)
24-
console.log(`[*] Searching block ${ i }`)
24+
console.log(`[*] Searching block ${ i }`);
2525
if (block && block.transactions) {
2626
for (let tx of block.transactions) {
27-
let transaction = await web3.eth.getTransaction(tx)
28-
console.log(transaction)
27+
let transaction = await web3.eth.getTransaction(tx);
2928
if (account === transaction.to.toLowerCase()) {
30-
console.log(`[+] Transaction found on block ${ lastBlockNumber }`)
31-
console.log({ address: transaction.from, value: web3.utils.fromWei(transaction.value, 'ether'), timestamp: new Date() })
29+
console.log(`[+] Transaction found on block ${ lastBlockNumber }`);
30+
console.log({ address: transaction.from, value: web3.utils.fromWei(transaction.value, 'ether'), timestamp: new Date() });
3231
}
3332
}
3433
}

transactionChecker2.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
1-
'use strict'
1+
'use strict';
22

33
module.exports = ({ web3, web3http }) => {
4-
const account = '0xe1Dd30fecAb8a63105F2C035B084BfC6Ca5B1493'.toLowerCase()
4+
const account = 'YOUR_ETH_ADDRESS'.toLowerCase();
55
const subscription = web3.eth.subscribe('pendingTransactions', (err, res) => {
6-
if (err) console.error(err)
7-
})
6+
if (err) console.error(err);
7+
});
88

99
return function watchTransactions() {
10-
console.log('[+] Watching transactions...')
10+
console.log('[+] Watching transactions...');
1111
subscription.on('data', (txHash) => {
1212
setTimeout(async () => {
1313
try {
14-
let tx = await web3http.eth.getTransaction(txHash)
15-
if (tx) {
14+
let tx = await web3http.eth.getTransaction(txHash);
15+
if (tx.to) {
1616
if (tx.to.toLowerCase() === account) {
17-
console.log({ address: tx.from, value: web3.utils.fromWei(tx.value, 'ether'), timestamp: new Date() })
17+
console.log({ address: tx.from, value: web3.utils.fromWei(tx.value, 'ether'), timestamp: new Date() });
1818
}
1919
}
2020
} catch (err) {
21-
console.error(err)
21+
console.error(err);
2222
}
23-
})
24-
})
23+
}, 60 * 1000);
24+
});
2525
}
26-
2726
}

0 commit comments

Comments
 (0)