1

I'm currently trying to listen to contract events from a contract address but on pending transactions. But I only got confirmed transaction on the instead of pending. Here my code

let subscription = web3.eth.subscribe("logs", {
  fromBlock: "pending",
  address: ["0x0eD7e52944161450477ee417DE9Cd3a859b14fD0"],
  topics: [], 
});

subscription.on("data", async (event) => {
  const tx = await web3.eth.getTransaction(event.transactionHash);
  console.log("tx", tx); //this is confirmed transaction because it has block number in it
});

How to listen events only for pending transactions ?

1
  • event logs are fired and saved after transactions are mined and successful. pending transactions can't emit events. Aug 14, 2021 at 9:16

1 Answer 1

2

subscribe for events for pending transactions not possible. event executed only when call function in smartcontract. so, if transaction have status pending - any events not executed.

Your Answer

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

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