About spacetimedb-procedures
A skill for developers building SpacetimeDB procedures outside reducer transaction entrypoints. It explains when to use procedures, how to shape them across supported languages, and how to handle transactions and external HTTP work.
Key features
- 01Procedure patterns across languages
- 02Guidance on return values and database access
- 03Transaction-safe database writes
- 04External HTTP and secret-handling guidance
Use cases
- 01Choosing between a reducer and a procedure
- 02Implementing procedures in SpacetimeDB
- 03Fetching external data before database writes
Install
Copy the command and run it in a terminal.
npx skills add https:/ / github.com/ danmossa/ spacetimedb-skills --skill spacetimedb-proceduresAfter installing, type/spacetimedb-proceduresin Claude Code to confirm it loaded.
Bundled filesreferences/functions-procedures.md
Details
From the project READMEUse this skill for procedures and server-side work that is not a reducer transaction entrypoint.
Core procedure patterns
Procedures are server functions that can return values and perform work that reducers should not do, including external HTTP calls. Use reducers for client-invoked transactional state changes; use procedures when the caller needs a return value or the function must do external work.
TypeScript procedure shape:
export const add_two_numbers = spacetimedb.procedure(
{ lhs: t.u32(), rhs: t.u32() },
t.u64(),
(_ctx, { lhs, rhs }) => BigInt(lhs) + BigInt(rhs),
);
Language notes:
- TypeScript procedures return the declared
t.*type and receive(ctx, args). - C# procedures are unstable; add
#pragma warning disable STDB_UNSTABLEand use[SpacetimeDB.Procedure]. - Rust procedures are unstable; enable the
unstablefeature and use#[spacetimedb::procedure]with&mut ProcedureContext. - C++ procedures are unstable; define
SPACETIMEDB_UNSTABLE_FEATURESbefore including the header.
Transactions and HTTP
- Procedures do not automatically run in a transaction.
- Wrap database writes in the language's transaction helper, such as TypeScript
ctx.withTx(...). - Do not hold a transaction open while making HTTP requests. Fetch first, then open a short transaction to write results or call reducer logic.
- Treat external API secrets and failures explicitly; do not log tokens or response bodies that may contain private data.
- If a procedure calls reducer logic, keep the shared state-changing logic transaction-safe and reusable from reducer context.
Reference map
| Need | Open |
|---|---|
| Procedure definitions, database access, HTTP, reducer calls, and return values | references/functions-procedures.md |
Guidance
- Use reducers for transactional client-invoked state changes; use procedures when the reference indicates return values or external work are appropriate.
- Keep HTTP request and external API handling explicit about secrets, failures, and runtime expectations.
- Route table mutation details to spacetimedb-reducers or spacetimedb-tables as needed.