Skip to content

getEvents

Usage

connect() must be called and a connection must be initiated before account information will be returned.

The getEvents() function returns events for a given 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.functionId}</p>
})}
</div>
)}
{ error && <p>error fetching events: {error}</p> }
</div>
);
}

Types

enum EventType {
Deploy = 'Deploy',
Execute = 'Execute',
Send = 'Send',
Receive = 'Receive',
Join = 'Join',
Split = 'Split',
Shield = 'Shield',
Unshield = 'Unshield',
Referral = 'Referral',
Points = 'Points',
/// arcade
Spin = 'Spin',
Raffle = 'Raffle',
Mint = 'Mint',
GiveawayEntry = 'Giveaway Entry',
GiveawayWin = 'Giveaway Win',
SquashMint = 'Squash Mint',
SquashWater = 'Squash Water',
SquashLevelUp = 'Squash Level Up',
MysteryCity = 'Mystery City',
}
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;
broadcastHeight?: number;
settled?: Date;
network: Network;
transactionId?: string;
height?: number;
description?: string;
visibility: Visibility;
fee: number;
feeCovered?: boolean;
feeCoverageType?: CoverageType;
functionId?: string;
programId?: string;
inputs: string[];
transitions: EventTransition[];
feeTransition?: EventTransition;
error?: string;
tokenIds?: string[];
puzzlePoints?: number;
coins?: number;
transaction?: Transaction;
}
type EventsFilter = {
type?: EventType;
programId?: string;
functionId?: string;
};
type GetEventsRequest = {
filter?: EventsFilter;
page?: number;
};
type GetEventsResponse = {
events: Event[];
pageCount: number;
};