Issue with checking transactions

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.

Hi there @mh133 Welcome to the Infura community.

let txChecker = new TransactionChecker(process.env.INFURA_ID, 'd21e93afd15342dfbbcd9459d3adca34')

for this line here, can you help to ensure that the Infura ID is getting pulled correctly from the .env file?
Also, I noticed the account is not an ethereum address?

Hi Lily,

Thank you for your interest in my case. I haven’t set any .env, would the following page help? https://blog.infura.io/how-to-use-dotenv-to-enhance-basic-security-within-your-dapp/

Thank you!