getLogs
Returns a list of event logs matching the provided parameters.
Usage
By default, getLogs returns all events. In practice, you must use scoping to filter for specific events.
import { } from "./client";
const = await .();
Output: [{ ... }, { ... }, { ... }]import { , } from "cive";
import { } from "cive/chains";
export const = ({
: ,
: (),
});Scoping
You can also scope to a set of given attributes.
import { } from "cive";
import { } from "./client";
const = await .({
: "cfx:...",
: (
"event Transfer(address indexed, address indexed, uint256)"
),
: 16330000n,
: 16330000n,
});import { , } from "cive";
import { } from "cive/chains";
export const = ({
: ,
: (),
});By default, event accepts the AbiEvent type:
import { } from "./client";
const = await .({
: "cfx:...",
: {
: "event",
: "Transfer",
: [
{ : "address", : true, : "from" },
{ : "address", : true, : "to" },
{ : "uint256", : false, : "value" },
],
},
: {
: "cfx:...",
: "cfx:...",
},
: 16330000n,
: 16330000n,
});import { , } from "cive";
import { } from "cive/chains";
export const = ({
: ,
: (),
});Address (Optional)
Logs can be scoped to an address:
const logs = await publicClient.getLogs({
address: "cfx:...",
});Event (Optional)
Logs 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 { parseAbiItem } from "cive";
const logs = await publicClient.getLogs({
address: "cfx:...",
event: parseAbiItem(
"event Transfer(address indexed from, address indexed to, uint256 value)"
),
});Arguments (Optional)
Logs 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.
An 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 Range (Optional)
Logs can be scoped to a epoch range:
import { } from "cive";
const = await .({
: "cfx:...",
: (
"event Transfer(address indexed from, address indexed to, uint256 value)"
),
: 16330000n,
: 16330050n,
});Or Epoch tag
import { } from "cive";
const = await .({
: "cfx:...",
: (
"event Transfer(address indexed from, address indexed to, uint256 value)"
),
: "earliest",
: "latest_state",
});Block Range (Optional)
Logs 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,
});blockHashes (Optional)
Array of up to 128 block hashes that the search will be applied to. This will override from/to epoch fields if it's not null.
import { } from "cive";
const = await .({
: "cfx:...",
: (
"event Transfer(address indexed from, address indexed to, uint256 value)"
),
: ["0x...", "0x..."],
});Multiple Events
Logs 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: Logs scoped to multiple events cannot be also scoped with indexed arguments (args).
Strict Mode
By default, getLogs 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)"
),
});
[0].args;
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,
});
[0].args;
Returns
A list of event logs.