Developer Docs
05 / 10
Server Actions
All server actions — what they do, who can call them, and where to find them.
All server actions live in src/app/actions/. They are Next.js server actions ("use server") called directly from client components. Each action that mutates data requires a Privy access token as its first argument.
competition.ts
| Action | Auth | Description |
|---|---|---|
| createCompetition(token, input) | Organizer | Validates input and creates a draft competition. Returns { slug, organizerSlug }. No escrow is deployed here. |
| getEscrowDeployParams(token, slug) | Organizer (owner) | Returns the arguments for the organizer's wallet to call factory.createEscrow. |
| recordEscrowDeployment(token, slug, txHash) | Organizer (owner) | Verifies the EscrowCreated event (competition id, token, shares, organizer wallet ∈ user's Privy wallets) and stores the escrow address. |
| recoverEscrowDeployment(token, slug) | Organizer (owner) | Finds and verifies an escrow already deployed at its deterministic address, for when recording was interrupted. |
| publishCompetition(token, slug) | Organizer (owner) | Moves a funded draft from draft → open. Reads totalContributed on-chain before publishing. |
| saveDraft(token, slug, input) | Organizer (owner) | Saves changes to a draft competition without publishing. |
entry.ts
| Action | Auth | Description |
|---|---|---|
| getMyEntry(token, competitionId) | Submitter | Returns the caller's entry for a competition, or null. |
| saveEntry(token, competitionId, input, submit) | Submitter | Upserts an entry. Pass submit: true to finalise. Assigns anonymous_id on first submission. |
| setEntryVisibility(token, entryId, hidden) | Submitter (owner) | Show or hide entry from public gallery. Winning entries cannot be hidden. |
organizer.ts
| Action | Auth | Description |
|---|---|---|
| getMyOrganizer(token) | Organizer | Returns the caller's organizer record, or null. |
| getOrganizerDashboard(token) | Organizer | Returns all competitions for the caller with entry counts. |
| getCompetitionEntries(token, competitionId) | Organizer (owner) | Returns all non-withdrawn entries. Submitter identity is stripped when status ≠ announced — anonymous judging enforcement. |
| prepareWinnerPayout(token, competitionId, picks, jurySummary) | Organizer (owner) | Validates picks (after deadline, submitted entries, every tier filled when escrowed) and returns winner wallets resolved from Privy, in tier order. |
| announceWinners(token, competitionId, picks, jurySummary, txHash?) | Organizer (owner) | For escrowed competitions, verifies the WinnersAnnounced event paid exactly the resolved winners; then saves results and moves the competition to announced. |
| updateCompetitionDeadline(token, competitionId, newDeadline) | Organizer (owner) | Extend deadline. Rules: any change within 24h of creation; extension-only after that, capped at 90 days past original. |
profile.ts
| Action | Auth | Description |
|---|---|---|
| getMyProfile(token) | Any | Returns the caller's organizer or submitter record. |
| updateProfile(token, input) | Any | Upsert profile. Creates record on first call. |
registration.ts
| Action | Auth | Description |
|---|---|---|
| registerForCompetition(token, competitionId) | Submitter | Register intent to submit. Records wallet address at registration time for lapse protection. |
| getMyRegistration(token, competitionId) | Submitter | Returns registration status for one competition. |
questions.ts
| Action | Auth | Description |
|---|---|---|
| askQuestion(token, competitionId, question) | Submitter | Submit a question to the organizer. |
| answerQuestion(token, questionId, answer) | Organizer (owner) | Answer a question and make it public. |
| getQuestions(competitionId) | Public | Returns all public Q&A for a competition. |
draft.ts
| Action | Auth | Description |
|---|---|---|
| saveDraftCompetition(token, input) | Organizer | Save competition data without triggering escrow deployment. |
Error handling pattern
All actions throw a plain Error with a human-readable message. Client components catch these and surface them in the UI:
try {
await someAction(token, args);
} catch (e) {
setError(e instanceof Error ? e.message : "Something went wrong.");
}
Actions never return error objects — a thrown error always means the operation did not complete.