Skip to content

Getting block timestamp in contract events without calling the getBlock() promise #1250

@tonypeng

Description

@tonypeng

👋 love the library! is there any way to get the timestamp of the block in the contract.on event feed without having to use the async getBlock() function? Or is the block already cached and getBlock() essentially returns right away?

i.e. something like:

contract.on(filter, async (event) => {
  const ts = event.blockTimestamp;
});

For context, I'm loading a snapshot from a contract function which returns the block timestamp of the snapshot (instead of the block number), and trying to diff the event blocks with the snapshot block timestamp (to discard any events from before the snapshot).

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionQuestions, feedback and general information.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions