Skip to content

getEvents

Usage

connect() must be called and WalletConnect session must be initiated before account information will be returned.

The getEvents() function returns events for the currently selected account. A filter can be applied to return a subset of events.

import {
EventsFilter,
Event,
getEvents,
GetEventsResponse
} from '@puzzlehq/sdk-core';
import { useState } from 'react';
export const EventsPage = () => {
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | undefined>();
const [events, setEvents] = useState<Event[] | undefined>();
const [totalPageCount, setTotalPageCount] = useState(0);
const filter: EventsFilter = {
type: 'Send',
programId: 'credits.aleo',
functionId: 'transfer_private'
}
const onClick = async () => {
setLoading(true);
setError(undefined);
try {
const response: GetEventsResponse = await getEvents(filter);
setEvents(response.events);
setTotalPageCount(response.pageCount);
} catch (e) {
setError((e as Error).message);
} finally {
setLoading(false);
}
}
return (
<div>
<button
onClick={ onClick }
disabled={ loading }
>
fetch events
</button>
{ events && (
<div>
<p>there are {totalPageCount} pages of events</p>
{events.map((event) => {
<p>{event._id}</p>
<p>{event.status}</p>
<p>{event.transactionId}</p>
<p>{event.programId}</p>
<p>{event.funcitonId}</p>
})}
</div>
)}
{ error && <p>error fetching events: {error}</p> }
</div>
);
}

Types

enum EventType {
Unknown = 'Unknown',
Deploy = 'Deploy',
Execute = 'Execute',
Send = 'Send',
Receive = 'Receive',
Join = 'Join',
Split = 'Split',
Shield = 'Shield',
Unshield = 'Unshield',
}
enum EventStatus {
Creating = 'Creating',
Pending = 'Pending',
Settled = 'Settled',
Failed = 'Failed',
}
enum Visibility {
Private = 'Private',
Public = 'Public',
}
enum Network {
AleoTestnet = 'AleoTestnet',
AleoMainnet = 'AleoMainnet',
}
type Event = {
_id: string;
type: EventType;
owner: string;
status: EventStatus;
created: Date;
broadcast?: Date;
settled?: Date;
network: Network;
transactionId?: string;
height?: number;
description?: string;
fee: number;
functionId: string;
programId: string;
visibility: Visibility;
inputs: (string | null)[];
outputs: (string | null)[];
error?: string;
}
type EventsFilter = {
type?: EventType;
programId?: string;
};
type GetEventsRequest = {
filter?: EventsFilter;
page?: number;
};
type GetEventsResponse = {
events?: Event[];
pageCount?: number;
error?: string;
};