Skip to content

Your First Event

Send an event to DeltaBase in a few minutes

You signed up. Let’s put one fact in the log and read it back. No manifesto, just append, then readStream.

You will:

  1. Create an event store (name it something you will type in getEventStore, something cool like the-best-event-store-in-the-world, or keep it simple like my-event-store).
  2. Create an API key and export DELTABASE_API_KEY.
  3. Save index.ts, run it, peek at the dashboard or Studio.

In the dashboard, Create Event Store. Use a name like my-event-store so it lines up with the code below, or change the string in getEventStore('…') to whatever you picked.

Dashboard → API KeysCreate.

Copy the key once, then:

Terminal window
export DELTABASE_API_KEY='paste-your-key-here'

Install the SDK:

Terminal window
pnpm add @delta-base/server

Save as index.ts (same as onboarding):

import { DeltaBase } from '@delta-base/server';
const client = new DeltaBase({
apiKey: process.env.DELTABASE_API_KEY,
baseUrl: 'https://api.delta-base.com',
});
async function main() {
const eventStore = client.getEventStore('my-event-store');
// Append your first event
await eventStore.appendToStream('my-first-stream', [
{
type: 'user.created',
data: { name: 'Alice', email: 'alice@example.com' },
},
]);
// Read events back
const { events } = await eventStore.readStream('my-first-stream');
console.log('Events:', events);
}
main().catch(console.error);

For a local stack, point baseUrl at your dev API (see Local development) instead of https://api.delta-base.com.

Install a runner if you need one, then execute:

Terminal window
pnpm add -D tsx
pnpm dlx tsx index.ts

Dashboard → your event store → Events. You should see user.created on stream my-first-stream.

One append, one read. The stream id is just a string you choose; the event type and data are your fact. Everything else in event sourcing grows out of that loop.

Next stops: Event sourcing fundamentals for the mental model, or Banking system for a full tutorial.

Unauthorized: Check echo $DELTABASE_API_KEY.

Event store not found: getEventStore('my-event-store') must match the store name in the dashboard exactly.

Wrong API host: Use https://api.delta-base.com for production, or your local base URL for dev.

Append errors on a second run: The stream my-first-stream may already exist. Use a new stream id, or learn optimistic concurrency with expectedStreamVersion when you move past the first demo.