const ethers = require('ethers');

// Initialize connection to the node.
const nodeUrl = "CHAINSTACK_NODE_URL";
const provider = new ethers.JsonRpcProvider(nodeUrl);

// Import and parse ABI for ERC-20 standard.
const abi = [
    // In this case, we only import the 'Transfer' event part of the ABI.
    "event Transfer(address indexed from, address indexed to, uint amount)"
];

// Create contract instance using an ERC-20 contract address and ABI.
const address = '0x4d224452801ACEd8B2F0aebE155379bb5D594381' // APE token
const contract = new ethers.Contract(address, abi, provider)

async function getLogs() {

    // Edit the range of blocks that you want to get logs from
    const range = 100;  // Get logs from the past 100 blocks
    const latestBlock = await provider.getBlockNumber()
    const from = latestBlock - range

    // queryFilter takes the name of the event and from and to block as parameters.
    const transferEvents = await contract.queryFilter('Transfer', from, latestBlock)
    return transferEvents
}

async function main() {
    const ape_logs = await getLogs();
    //console.log(ape_logs) // Print full logs

    // Parse the logs and extract only tx hash, from address, to address, and amount transferred.
    for (let object of ape_logs){
        console.log(`Transaction hash of APE transfer: ${object.transactionHash}`)
        console.log(`From: ${object.args.from}`)
        console.log(`To: ${object.args.to}`)
        console.log(`Amount of APE transferred: ${ethers.formatEther(String(object.args.amount))} \n`)
    }
}

main()
$ node index

Transaction hash of APE transfer: 0x3125accac13704e1bb017021dd385293e79c7bc3b1090fd82df690249116c5d4
From: 0x74de5d4FCbf63E00296fd95d33236B9794016631
To: 0x51C72848c68a965f66FA7a88855F9f7784502a7F
Amount of APE transferred: 782.652322144396771286
const ethers = require('ethers');

// Initialize connection to the node.
const nodeUrl = "CHAINSTACK_NODE_URL";
const provider = new ethers.JsonRpcProvider(nodeUrl);

// Import and parse ABI for ERC-20 standard.
const abi = [
    // In this case, we only import the 'Transfer' event part of the ABI.
    "event Transfer(address indexed from, address indexed to, uint amount)"
];

// Create contract instance using an ERC-20 contract address and ABI.
const address = '0x4d224452801ACEd8B2F0aebE155379bb5D594381' // APE token
const contract = new ethers.Contract(address, abi, provider)

async function getLogs() {

    // Edit the range of blocks that you want to get logs from
    const range = 100;  // Get logs from the past 100 blocks
    const latestBlock = await provider.getBlockNumber()
    const from = latestBlock - range

    // queryFilter takes the name of the event and from and to block as parameters.
    const transferEvents = await contract.queryFilter('Transfer', from, latestBlock)
    return transferEvents
}

async function main() {
    const ape_logs = await getLogs();
    //console.log(ape_logs) // Print full logs

    // Parse the logs and extract only tx hash, from address, to address, and amount transferred.
    for (let object of ape_logs){
        console.log(`Transaction hash of APE transfer: ${object.transactionHash}`)
        console.log(`From: ${object.args.from}`)
        console.log(`To: ${object.args.to}`)
        console.log(`Amount of APE transferred: ${ethers.formatEther(String(object.args.amount))} \n`)
    }
}

main()
$ node index

Transaction hash of APE transfer: 0x3125accac13704e1bb017021dd385293e79c7bc3b1090fd82df690249116c5d4
From: 0x74de5d4FCbf63E00296fd95d33236B9794016631
To: 0x51C72848c68a965f66FA7a88855F9f7784502a7F
Amount of APE transferred: 782.652322144396771286