Hi,
I have tried to replicate the tutorial posted here, but without success: https://www.youtube.com/watch?v=GSLEz-XxGY8
Here is my code:
const Web3 = require('web3');
class TransactionChecker {
web3;
account;
constructor(projectId, account) {
this.web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/v3/' + projectId));
this.account = account.toLowerCase();
}
async checkBlock() {
let block = await this.web3.eth.getBlock('latest');
let number = block.number;
console.log('Searching block ' + number);
if (block != null && block.transactions != null) {
for (let txHash of block.transactions) {
let tx = await this.web3.eth.getTransaction(txHash);
if (this.account == tx.to.toLowerCase()) {
console.log('Transaction found on block: ' + number);
console.log({address: tx.from, value: this.web3.utils.fromWei(tx.value, 'ether'), timestamp: new Date()});
}
}
}
}
}
let txChecker = new TransactionChecker(process.env.INFURA_ID, 'd21e93afd15342dfbbcd9459d3adca34');
setInterval(() => {
txChecker.checkBlock();
}, 15 * 1000);
But all I am getting is “Error: Invalid JSON RPC response: “invalid project id\n””. Not sure why.
Could anyone help please? I’m new to this.