2

I have created a Node project that connects to Alchemy via ethers. I am trying to capture all Supply events for AaveV3

However, when I use the getLogs function, and use the contract address as the address field, it finds no event logs whatsoever.

const AAVE_V3_CONTRACT_ADDRESS = '0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2'; 
const provider = new ethers.AlchemyProvider('mainnet', ALCHEMY_API_KEY);

async function fetchSupplyEvents(minAmount, maxAmount) {
   const logs = await provider.getLogs({
      address: AAVE_V3_CONTRACT_ADDRESS,
   });
   console.log(logs); //returns []
   ...

You might have noticed, I have totally omited most fields from the getLogs function, because it seems to be unable to capture ANY events that have happened to this contract. There have definitely been events omited, see the link above.

So my question is

Why is Alchemy failing to find any logs when I call eth_getLogs?

1 Answer 1

0

You are missing the topics field in the filter object you're passing to getLogs, you need to include the event signature in the topics field.

You gonna to find the signature of the Supply event in AaveV3, you can have it like that const supplyEventSignature = ethers.utils.id("Supply(address,address,uint256,uint256)");

here is the full code, dont forget to replace the ALCHEMY_API_KEY

const ethers = require("ethers");

const ALCHEMY_API_KEY = 'your_alchemy_api_key';
const AAVE_V3_CONTRACT_ADDRESS = '0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2';
const provider = new ethers.AlchemyProvider('mainnet', ALCHEMY_API_KEY);

const supplyEventSignature = ethers.utils.id("Supply(address,address,uint256,uint256)");

async function fetchSupplyEvents(minAmount, maxAmount, fromBlock = 0, toBlock = 'latest') {
    const logs = await provider.getLogs({
        address: AAVE_V3_CONTRACT_ADDRESS,
        topics: [supplyEventSignature],
        fromBlock,
        toBlock,
    });

    console.log(logs);
}

fetchSupplyEvents();
1
  • According to the docs, topics is an optional field. Apr 12, 2023 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.