Skip to content
Cive

createEventFilter

Creates a Filter to listen for new events that can be used with getFilterChanges.

Usage

By default, an Event Filter with no arguments will query for/listen to all events.

import {  } from "./client";
 
const  = await .();
{ id: "0xbfb021a4ab99e28173cb75bffbda39fc", type: 'event' }

Scoping

You can also scope a Filter to a set of given attributes (listed below).

Address

A Filter can be scoped to an address:

import {  } from "./client";
 
const  = await .({
  : "cfx:...", 
});

Event

A Filter can be scoped to an event.

The event argument takes in an event in ABI format – we have a parseAbiItem utility that you can use to convert from a human-readable event signature → ABI.

import {  } from "cive"; 
import {  } from "./client";
 
const  = await .({
  : "cfx:...",
  : (
    "event Transfer(address indexed from, address indexed to, uint256 value)"
  ), 
});

By default, event accepts the AbiEvent type:

import {  } from "./client";
 
const  = await .({
  : "cfx:...",
  : {
    : "Transfer",
    : "event",
    : [
      { : "address", : true, : "from" },
      { : "address", : true, : "to" },
      { : "uint256", : false, : "value" },
    ],
  },
});

Arguments

A Filter can be scoped to given indexed arguments:

import {  } from "cive";
 
const  = await .({
  : "cfx:...",
  : (
    "event Transfer(address indexed from, address indexed to, uint256 value)"
  ),
  : {
    : "cfx:...",
    : "cfx:...",
  },
});

Only indexed arguments in event are candidates for args.

A Filter Argument can also be an array to indicate that other values can exist in the position:

import {  } from "cive";
 
const  = await .({
  : "cfx:...",
  : (
    "event Transfer(address indexed from, address indexed to, uint256 value)"
  ),
  : {
    : ["cfx:...", "cfx:...", "cfx:..."],
  },
});

Epoch Tag

A Filter can be scoped to a epochTag range:

import {  } from "cive";
 
const  = await .({
  : "cfx:...",
  : (
    "event Transfer(address indexed from, address indexed to, uint256 value)"
  ),
  : "earliest", 
  : "latest_state", 
});

Epoch number

A Filter can be scoped to a epoch number range:

import {  } from "cive";
 
const  = await .({
  : "cfx:...",
  : (
    "event Transfer(address indexed from, address indexed to, uint256 value)"
  ),
  : 1n, 
  : 19n, 
});

Block Range

A Filter can be scoped to a block range:

import {  } from "cive";
 
const  = await .({
  : "cfx:...",
  : (
    "event Transfer(address indexed from, address indexed to, uint256 value)"
  ),
  : 16330000n, 
  : 16330050n, 
});

Multiple Events

A Filter can be scoped to multiple events:

import {  } from "cive";
 
const  = await .({
  : ([
    "event Approval(address indexed owner, address indexed sender, uint256 value)",
    "event Transfer(address indexed from, address indexed to, uint256 value)",
  ]),
});

Note: A Filter scoped to multiple events cannot be also scoped with indexed arguments (args).

Strict Mode

By default, createEventFilter will include logs that do not conform to the indexed & non-indexed arguments on the event. cive will not return a value for arguments that do not conform to the ABI, thus, some arguments on args may be undefined.

import {  } from "cive";
 
const  = await .({
  : "cfx:...",
  : (
    "event Transfer(address indexed from, address indexed to, uint256 value)"
  ),
});
const  = await .({  });
 
[0].argsArrow
;

You can turn on strict mode to only return logs that conform to the indexed & non-indexed arguments on the event, meaning that args will always be defined. The trade-off is that non-conforming logs will be filtered out.

import {  } from "cive";
 
const  = await .({
  : "cfx:...",
  : (
    "event Transfer(address indexed from, address indexed to, uint256 value)"
  ),
  : true,
});
const  = await .({  });
 
[0].argsArrow
;

Returns

Filter

Parameters

address (optional)

  • Type: Address | Address[]

The contract address or a list of addresses from which Logs should originate.

const  = await .({
  : "cfx:...", 
});

event (optional)

The event in ABI format.

A parseAbiItem utility is exported from cive that converts from a human-readable event signature → ABI.

import {  } from "cive"; 
 
const  = await .({
  : "cfx:...",
  : (
    "event Transfer(address indexed from, address indexed to, uint256 value)"
  ), 
});

args (optional)

  • Type: Inferred.

A list of indexed event arguments.

import {  } from "cive";
 
const  = await .({
  : "cfx:...",
  : (
    "event Transfer(address indexed from, address indexed to, uint256 value)"
  ),
  : {
    : "cfx:...",
    : "cfx:...",
  },
});

Epoch number (Optional)

Logs can be scoped to a epoch range:

 
const  = await .({
  : 16330000n, 
  : 16330050n, 
});

Epoch tag (Optional)

 
const  = await .({
  : "earliest", 
  : "latest_state", 
});

fromBlock (optional)

  • Type: bigint

Block to start querying/listening from.

const  = await .({
  : 69420n, 
});

toBlock (optional)

  • Type: bigint

Block to query/listen until.

const  = await .({
  : 70120n, 
});

JSON-RPC Methods

cfx_newFilter