π I've built two more demos for state machines on #nostr β this time involving #cashu, with a few interesting use cases around custody and betting. β‘
In addition I've made the explanations more verbose and understandable, and rendered a video for every demo with Remotion π¬. The actors are now generatable per demo and persist across sessions.
Enjoy on
https://schlaustronics.com/nsm π
Source:

GitHub
GitHub - zeSchlausKwab/nsm: nostr state machines demos
nostr state machines demos. Contribute to zeSchlausKwab/nsm development by creating an account on GitHub.
π
β
/nsm/wager - Wager Β· decentralized escrow
The custodian holds nothing. Bettors lock stakes into 2-of-2 Cashu multisig and pre-sign every possible outcome; the oracle's only power is choosing which pre-signed package gets the second signature. The mint enforces β no party can steal.
/nsm/bet - Bet Β· oracle-resolved betting
Two bettors stake Cashu against an outcome. An oracle publishes what happened, and a payout scroll computes the winnings deterministically. Anyone replaying the chain can re-run the scroll and get the same numbers.
/nsm/counter - Counter Β· the smallest interesting state machine
Two players race to a target on a shared counter. Every interaction is a signed Nostr event on a single relay β no APIs, no shared database, no off-band coordination.
/nsm/rps - Rock Paper Scissors Β· fair play via commit-reveal
Both players publish a sha256 commit of their move before either reveals. The custodian re-hashes each reveal to verify it matches the prior commit before snapshotting.
/nsm/vote - Vote Β· time-driven voting
A roster of voters casts yes/no until the deadline. The custodian fires CLOSE_VOTING and FINALIZE herself β but both are gated by the SM's own deadline guard, so any watchtower can verify she didn't close early.
/nsm/badges - Badges Β· transferable digital assets
One shared kind:7500 ownership state machine, many minted kind:7503 badges, each with its own ownership chain under d-tag = imageHash. Transfers require m-of-n validator cosigns.
/nsm/scroll-counter - Scroll Counter Β· state machine with pluggable rules
Counter shape, but guards and actions are AssemblyScript-compiled WASM blobs (scrolls) published as kind:1227 events. Swap the engine tag, get different rules β the SM definition itself never changes.
/nsm/negotiator - Negotiator Β· propose, agree, spawn
Two parties iterate on a state machine definition until they agree, then a jukebox spawns the negotiated SM and reports the new machineId back. The negotiation transcript IS the contract.
/nsm/nested - Nested Β· parent + child state machines
A tournament parent SM invokes two child match SMs. Every snapshot carries the children's live state alongside the parent's β readable straight off the relay, no extra subscriptions.
/nsm/pool - Pool Β· decentralized-custody crowdfunding
Three stakers lock Cashu P2PK to a target with a refund timelock back to themselves. Majority yes funds the target; the custodian never touches the money β the mint enforces everything.
View quoted note β