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 durableAccount actor type — but each account name is its own isolated instance:
debit never overdraws, and a committed debit is never lost.
Why an Account
AnAccount exercises the three properties a Stateful Actor gives you:
- Per-instance isolation —
aliceandbobare 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-edgeCLI, installed and authenticated — a release with Stateful Actor deploy support. v0.2.2 and earlier cannot ship an actor project (new-func --actorappears to work, butshipfails); upgrade from the releases page. - A Telnyx API key.
- Node.js (for
npm).
1. Authenticate
2. Scaffold the Actor Project
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 withsrc/account.ts. It holds one value — the balance — in this.ctx.storage:
4. Write the Fetch Handler
Replacesrc/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 ACCOUNT → Account:
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:
aliceends at 70 (100 − 30; the 1000 debit was rejected)bobis independent at 5aliceis unchanged bybob’s activity (isolation), and survives across requests (persistence)
Next Steps
- Shared Actors — add a second function that reads/writes the same
Accountthrough a different binding - Runtime API —
StatefulActor,ctx,storage, alarms - Alarms — schedule deferred work from inside an actor method