0

I'm using web3.js library to subscribe to ERC20 token transfer events on a blockchain:

const logOptions = {
   // Filter transfer topics 
   topics: [
       web3.utils.sha3('Transfer(address,address,uint256)')
   ]
};

let subscription = web3.eth.subscribe('logs', logOptions);

subscription.on('data', async (event: any) => {
    // `event` contains the transfer info
});

I get an event emitted for any transfer triggered by a transaction, but I wish I would get an event saying the transaction is done - which means all transfers were made.

Any way to it using web3.js, or maybe another library?

1 Answer 1

1

Logs are not emitted until a transaction is mined in a block. This is the common definition to see when a transaction is done.

Thus, the code you describe works correctly and only sees logs from done transactions.

1
  • So, can I know when all of the logs are emitted(and I can return from my function for example)? I guess I can use setTimeout(()=>{ ... }, 50) if we can assume that all of the logs emitted at the same time, but I', looking for a more elegant method, like an "allLogsEmitted" event.
    – benams
    Commented Jan 25, 2023 at 13:04

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.