Skip to content

createEvent

Usage

connect() must be called and WalletConnect session must be initiated.

The createEvent() function requests the creation of an onchain transaction from a user.

We use the term “event” rather than “transaction” because not all onchain transactions are financial in nature.

Here are the event types you can request creation for:

enum EventType {
Deploy = 'Deploy',
Execute = 'Execute',
Send = 'Send',
Join = 'Join',
Split = 'Split',
Shield = 'Shield',
Unshield = 'Unshield'
}

Here is the request payload you need to define:

type CreateEventRequestData = {
address?: string;
type: EventType;
programId: string;
functionId: string;
fee: number;
inputs: (Record | string)[];
};

The optional address field can be used to request event creation on behalf of a shared state account instead of the connected user.

import { createSharedState, requestCreateEvent } from '@puzzlehq/sdk-core';
import { EventType } from '@puzzlehq/types';
import { useState } from 'react';
function CreateEventPage() {
/// your specific function inputs go in here!
const [inputs, setInputs] = useState<any>({});
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | undefined>();
const [eventId, setEventId] = useState<string | undefined>();
const onClick = async () => {
setLoading(true);
const createEventResponse = await requestCreateEvent({
type: EventType.Execute,
programId: 'program_name_here.aleo',
functionId: 'function_name_here',
fee: 1.23,
inputs: Object.values(inputs)
});
if (createEventResponse.error) {
setError(createEventResponse.error);
} else {
setEventId(createEventResponse.eventId);
}
setLoading(false);
};
return (
<div>
<button
onClick={ onClick }
disabled={ loading }
>
create event
</button>
{ eventId && <p>event pending: {eventId}</p> }
{ error && <p>error creating event: {error}</p> }
</div>
);
}

Types

export type CreateEventRequestData = {
address?: string;
type: EventType;
programId: string;
functionId: string;
fee: number;
inputs: (Record | string)[]; // inputs should be in the same order as the program inputs
};
export type CreateEventResponse = {
eventId?: string;
error?: string;
};

Additional related types can be found on the events page.