Skip to main content
Ship an Account actor end-to-end: scaffold, write the class, deploy, and curl it. Each account name is its own actor instance — alice and bob are isolated, each with their own balance, all persisted. Roughly 10 minutes.

What You’ll Build

A function with routes that all share a single durable Account actor type — but each account name is its own isolated instance:
A debit never overdraws, and a committed debit is never lost.

Why an Account

An Account exercises the three properties a Stateful Actor gives you:
  • Per-instance isolationalice and bob are separate actor instances with their own balance.
  • Single-threaded dispatch — concurrent debits on the same account serialize automatically. No lock, no race: two debits can’t both pass the balance check.
  • Persistence — the balance survives across requests; it’s durable and reloaded when the actor is next invoked.

Prerequisites

  • The telnyx-edge CLI, installed and authenticated — a release with Stateful Actor deploy support. v0.2.2 and earlier cannot ship an actor project (new-func --actor appears to work, but ship fails); upgrade from the releases page.
  • A Telnyx API key.
  • Node.js (for npm).

1. Authenticate

2. Scaffold the Actor Project

This writes an umbrella telnyx.toml (with a [[actors]] block), a sample actor class, a fetch handler, and registers the function (writes a func_id into telnyx.toml). npm install pulls in @telnyx/edge-runtime.

3. Write the Account Actor

Replace the scaffolded actor class with src/account.ts. It holds one value — the balance — in this.ctx.storage:

4. Write the Fetch Handler

Replace src/index.ts with a handler that routes HTTP to actor method calls. It re-exports the actor class (so it ships with the bundle) and calls it through the ACCOUNT binding on env:

5. Update telnyx.toml

Point the [[actors]] binding at your class. The scaffold generated a sample binding; change it to ACCOUNTAccount:

6. Deploy

ship bundles the project, uploads it, and monitors the deploy — wait for ✅ Func 'account' is now deployed! (in telnyx-edge list, the function’s status becomes deploy_ok).

7. Hit the URL

ship prints a URL like account-<id>.telnyxcompute.com. The function may take a moment to come up — poll the health endpoint until it returns 200:
Now exercise it — two accounts, no overdraw, isolation, persistence:
You should see:
  • alice ends at 70 (100 − 30; the 1000 debit was rejected)
  • bob is independent at 5
  • alice is unchanged by bob’s activity (isolation), and survives across requests (persistence)

Next Steps

  • Shared Actors — add a second function that reads/writes the same Account through a different binding
  • Runtime APIStatefulActor, ctx, storage, alarms
  • Alarms — schedule deferred work from inside an actor method