
Legilimens
Stake 1 USDC and challenge an on-chain agent to guess your job in 10 questions
Demo
About
Legilimens is an on-chain fortune booth. You stake 1 USDC, secretly pick your job, and answer 10 yes/no style questions. The Seer, an autonomous agent with its own wallet, then guesses your job. If it names your exact job, it keeps your stake. If it misses, you win your stake back plus half the pot. How it stays fair: - Your job is locked on-chain as a hash before the first question, so you cannot change it later and the Seer cannot see it. - The Seer commits to its question seed before you play, so it cannot change its strategy after seeing your answers. - The smart contract decides the result and pays out in the same transaction. - If you lie to trick the Seer, the contract checks whether your answers fit your sealed job. Answers that clearly do not fit forfeit your stake. - Anyone can replay any game with one command and check whether the Seer played fair. The Seer is not an LLM. It uses Bayesian inference (https://en.wikipedia.org/wiki/Bayesian_inference) over a published table of 66 jobs and 24 traits, similar to a naive Bayes classifier (https://en.wikipedia.org/wiki/Naive_Bayes_classifier). It picks each question by information gain (https://en.wikipedia.org/wiki/Information_gain_(decision_tree)), the classic twenty questions strategy (https://en.wikipedia.org/wiki/Twenty_questions). Built with: - Arc: USDC stakes, payouts and the Seer's wallet, which earns a 5% cut and pays its own gas. - The Graph: a subgraph of past games that the Seer learns from before each game. - ENS: the Seer's identity and settings live on seer.legilimens.eth. Each player gets a name like abc123.players.legilimens.eth with their game record, written only by the Seer. Players caught lying twice are refused.
How it's made
Legilimens has four parts: a smart contract on Arc, a Next.js app that also runs the Seer, a subgraph on The Graph, and ENS names on Sepolia. Smart contract (Solidity, Foundry) The LegilimensVault contract holds stakes and runs a commit-reveal game. The player locks their job as a hash with a secret salt. The Seer locks a hash of its random seed. When the Seer guesses, it publishes the seed plus the full transcript (which question it asked and each answer, packed into two bytes10 values). When the player reveals, the contract checks the hash, compares job codes, and pays out in one transaction. Winners take a share of the pot, never a fixed amount, so the pot can never pay out more than it holds. 27 Foundry tests cover every outcome, timeouts, bad signatures and a solvency check. The Seer (not an LLM) The Seer is a Bayesian solver written in TypeScript. It uses a table of 66 jobs and 24 traits, updates a probability for every job after each answer, and picks the next question by information gain. The pick uses a seeded softmax, so there is no fixed question tree to exploit, but any game can be replayed exactly. We tuned the question count and randomness with Monte Carlo simulations so the Seer wins about half the time. Hacky bits worth mentioning - Catching liars on-chain: a script turns the job table into Solidity constants. At reveal, the contract scores how well the answers fit the sealed job compared with every other job, using integer math. A Foundry test proves the contract and the TypeScript solver produce the exact same scores. Blatant liars forfeit their stake. In simulation this turned lying from a big profit into a loss. - No database: the server re-derives each game's secret seed from on-chain data, so it is completely stateless. - Deterministic learning: the Seer only learns from games settled before the current game started, so replays always rebuild the same starting beliefs. - A replay script rebuilds any game from public chain data and checks every question, the guess and the verdict. Partner technologies - Arc: USDC is the gas token, so stakes, payouts and the Seer's running costs are all in USDC with no conversion. The Seer has its own wallet, earns a 5% cut when it wins, pays its own gas, and records its costs on-chain. - The Graph: a subgraph indexes every game. The Seer reads it before each game to learn which jobs people pick, which changes the questions it asks. It also powers the live ledger of recent games. - ENS (ENSv2 on Sepolia): seer.legilimens.eth stores the Seer's wallet, agent records and the app's settings (vault address, subgraph URL, matrix hash). The app reads these at runtime instead of hard-coding them. The owner gave the Seer's wallet only two permissions: creating names under players.legilimens.eth, and writing specific record keys. After each game the Seer writes the player's record to their own name, like abc123.players.legilimens.eth. Players caught lying twice are refused. Frontend Next.js 16, React 19, Tailwind 4, Motion for animations, and wagmi and viem for the wallet. The whole game is designed as a candlelit fortune booth with a wax seal, scrying orb and a pot that fills up. Deployed on Vercel.