requestCreateEvent
Usage
connect()
must be called and connection session must be initiated.
The requestCreateEvent()
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; network?: Network; type: EventType; programId: string; functionId: string; fee: number; feeRecord?: RecordWithPlaintext; inputs: (RecordWithPlaintext | string)[]; tokenIds?: string[]; settlementInfo?: { eventId?: string; expectedRecordCount: number; currentRecordCount: number; };};
import { requestCreateEvent } from '@puzzlehq/sdk-core';import { EventType } from '@puzzlehq/types';import { useState } from 'react';
function CreateEventPage() { /// your specific function inputs go in here! 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: ['123u64'] }); 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
type CreateEventResponse = { eventId?: string; error?: string;};
Additional related types can be found on the events page.