← ALL ARTICLES

How I built a fully onchain board game on Solana with no server

Bankroll is a fully onchain board game on Solana for 2 to 4 players with no game server. Every roll, trade and payout runs on a MagicBlock Ephemeral Rollup.

A fully onchain board game with no server: a board game on top of an empty server rack

I built Bankroll, a fully onchain board game on Solana for 2 to 4 players, and it has no game server. Every table, turn, die roll and payout runs on a MagicBlock Ephemeral Rollup. Players never hold SOL and never approve a fee.

A board game is a bad fit for a normal blockchain. One game is a few hundred actions: rolls, buys, rent, builds, trades. At a fee and a wallet popup per action, nobody finishes a game. At 400 ms a block plus a separate randomness round trip, every roll feels like waiting for a page to load. The usual fix is to run the game on a server and only settle money on chain, which means players have to trust the server with both the dice and the pot.

I wanted the rules, the dice and the money in one Solana program that anyone can read, and I wanted it to play as fast as a web game. MagicBlock's Ephemeral Rollups gave me both.

The game

You roll one die around a 24-space board. You buy cities and public properties, build on them, collect rent, go to jail, draw Lucky cards and swap properties on the Auction space. The first player whose net worth reaches the target wins, or the last player standing. The host picks the board (Classic, Bangalore or Mumbai), the player count and the starting cash.

There's a small USDC pot under every game. Each seat pays an entry, and when the game ends the program pays the pot out by rank, minus a 3% fee. On devnet the entry is 0.001 USDC, so in practice it plays like a free game with real settlement underneath.

Here's what a new player does:

  1. Opens the site. The browser creates a wallet key and stores it encrypted in IndexedDB. No extension, no seed phrase.
  2. Presses Quick play. The app joins the fullest open lobby it can find, or opens a new table.
  3. Plays. Every roll, buy and trade is a signed transaction, but there's no popup and no fee, so it feels like clicking a button in a web game.
  4. Gets paid. When someone hits the target, any player's client sends one settle transaction and every seat gets its share.

What it looks like

The home screen asks for a name and a board, then offers two ways in: play a bot, or open a table for friends.

Bankroll home screen: enter a name, pick the Classic, Bangalore or Mumbai board, then play a bot or open a table for friends

On your turn you roll. When you land on something for sale, the buy card shows the price and the full rent table, and a turn timer counts down so nobody stalls.

A desktop table on the Classic board: the buy card for Airport shows the price and the full rent table while the turn timer runs

The log on the right lists every roll, purchase and rent payment as it confirms on the rollup. Each line is a transaction, and none of them cost the player anything.

A desktop table mid-game: the log on the right lists every roll, purchase and rent payment

On a phone the board fills the screen, players sit above it, and coins fly between seats when rent changes hands.

Bankroll on a phone: player cards above the board and coins flying between seats when rent changes hands

How it fits together

Architecture: only deposits and withdrawals touch Solana, every move runs on the MagicBlock Ephemeral Rollup

The browser talks to the rollup for every move. Solana itself only sees the one-time admin setup and the USDC moving in and out through the Payments API.

One turn looks like this:

  1. The player presses Roll. The browser signs a roll transaction and sends it to the rollup.
  2. The program checks it's that seat's turn and sends a VRF request for the table.
  3. The oracle calls consume_randomness with 32 random bytes, a median of 239 ms later. The program moves the pawn and applies rent, a Lucky card or jail.
  4. Every browser at the table sees the account change over the rollup's websocket and animates the move.
  5. When someone reaches the target, any client sends settle, which pays every seat from the vault in one transaction.

How MagicBlock powers a fully onchain Solana game

Bankroll uses five MagicBlock pieces. Each one replaces something I'd otherwise build or run myself.

MagicBlock pieceWhat it does in BankrollWhat it replaces
Ephemeral RollupRuns every game instruction, with no transaction feesA game server
Ephemeral AccountsCreate each table on the rollup only, paid for by a delegated house accountA pool of base-layer table accounts
VRFRolls the die and calls back into the program with the resultA dice server, or commit-reveal
Ephemeral SPL tokensMove USDC onto the rollup so entries and payouts are ordinary token transfers thereBridging, or settling every payout on base
Payments APISponsors the base-layer deposit and withdraw, so players never need SOLA relayer I'd host

A table lives only on the rollup

My first version kept four tables on Solana and delegated them to the rollup. That capped the game at four concurrent tables, and each one locked about 0.017 SOL of rent with no way to close it. Ephemeral Accounts fixed both. A house account, delegated once by the admin, pays the rent for a table that exists only on the rollup. A 566-byte table costs 20,032 lamports. A host with zero SOL calls open_table, and the program creates the table at a PDA keyed by the host's wallet:

EphemeralAccount::new(&house, &info, &accounts.rent_vault)
    .with_signer_seeds(&[house_seeds, table_seeds])
    .create(TABLE_SPACE as u32)?;

When a table has been idle for 10 minutes, anyone can close it, and the rent goes back to the house. With 0.1 SOL in the house, that's room for 4,992 open tables at once.

Verifiable dice rolls with MagicBlock VRF

A roll is a VRF request from inside the program. The request carries the table account and a nonce, and the oracle calls consume_randomness on the rollup with 32 random bytes:

create_request_randomness_ix(RequestRandomnessParams {
    payer,
    oracle_queue: DEFAULT_EPHEMERAL_QUEUE,
    callback_program_id: ID,
    callback_discriminator: instruction::ConsumeRandomness::DISCRIMINATOR.to_vec(),
    caller_seed: hashv(&[b"bankroll-vrf-v1", table.key().as_ref(), &table.vrf_nonce.to_le_bytes()]).to_bytes(),
    accounts_metas: Some(vec![SerializableAccountMeta { pubkey: table.key(), is_signer: false, is_writable: true }]),
    callback_args: Some(table.vrf_nonce.to_le_bytes().to_vec()),
})

The program checks the callback against its own VRF identity, so a spoofed callback fails. The program uses the randomness right away and never stores it, so nobody can read the next roll from public state. The nonce makes sure a late callback from an old game can't land in a new one. The player rolling pays for the request, from a wallet with zero SOL, because fees on the rollup are zero.

Money without SOL

A player's USDC reaches the rollup through the Payments API. The app asks for a gasless deposit, the API sponsor pays the base-layer fee, and the player signs. Each deposit or withdrawal costs 0.20 USDC, with a 0.50 USDC minimum. After that, an entry is a plain SPL transfer on the rollup into a shared vault owned by the house. The program records each table's share in a held field and the total in the house's liability. settle pays every seat from the vault in one transaction and sends the fee to the treasury.

The program never calls the ephemeral SPL program directly. It moves tokens between rollup-side token accounts and checks that each payout account is still delegated.

How I built it

I started with the economy, not the code. A Python simulation of the rules played thousands of games to set prices, rents and targets, so a game ends in a reasonable number of turns and seat order doesn't decide the winner. I wrote the Rust engine to the same rules. A fuzz test then played 91,000 games through the real engine, and the results stayed within about 4% of the simulation.

Before writing the full program, I ran two small spikes on devnet to check the parts I wasn't sure of. Can a wallet with zero SOL pay for its own VRF request on the rollup? Yes. Does the VRF SDK reject a callback that didn't come from the oracle? Also yes. Both answers made the design simpler. I didn't need a fee-payer account for randomness or extra checks in the callback.

Then I built it in phases. First came the core loop with a staked lobby, then the full rules, Auction trades, an audit and the UI. A LiteSVM suite ran against devnet copies of the VRF program and the rollup's oracle queue. Each phase ended with a bot game on devnet, where zero-SOL wallets played to the end and the script checked every payout to the last unit.

These are the problems that changed the design:

ProblemWhat happenedFix
Games nobody finishesPlayers close the tab, and the pot stays stuckEvery game ends 60 minutes after the last action. Any seated client then sends one force_timeout and settle to rank and pay it
No server to run timeoutsLobbies expire, stages time out, VRF requests get droppedEach open tab runs a small crank. It reads the table, works out the action due, and sends it after 0 to 3 seconds of random jitter so tabs rarely race
One bad account blocks a payoutA player who closed their token account would make settle fail for everyonesettle pays the live seats and holds the missing seat's share for 30 minutes, then sends it to the treasury
SOL sent to a table addressIf someone sends SOL to a host's table PDA on Solana first, the rollup sees a system account there and refuses to create the tableA permissionless unblock_table on base sweeps the SOL to the caller, and the client retries. The audit found this, and I reproduced it on devnet before fixing it
Four tables isn't enoughThe base-layer pool capped concurrent gamesTables moved to Ephemeral Accounts, created on demand
Funding new playersThe Payments API only accepts approved stablecoins for gasless depositsA devnet USDC faucet tops up a new wallet once. At a 0.001 USDC entry, that covers about 500 games

I ran a Solana security audit after every phase that touched the program. It found three medium issues across the build. I fixed all three, and nothing above informational is open.

Numbers

A roll comes back in about a quarter of a second, and a player spends nothing but their entry. These figures come from a devnet capacity run with 25 tables and 50 seats playing at once, plus the bot games at the end of each phase.

MeasureResult
Roll to result (VRF request to callback), median239 ms
Roll to result, 95th percentile465 ms
VRF retries in the capacity run0
SOL a player needs0
Fee per game action0
Moving USDC in or out0.20 USDC each way
Rent per table, paid by the house and refunded on close20,032 lamports
Open tables that 0.1 SOL of house rent covers4,992
Worst-case VRF callback compute17,638 CU

Try it, or build your own

Bankroll is live on devnet, and the code is open.

  • Play: bankroll-er.vercel.app. Press Quick play, or play a bot first.
  • Code: github.com/dhruvja/bankroll-er. The program, the client with the crank, the operator scripts and the tests.
  • Start your own: the gasless starter in the MagicBlock examples repo has the same zero-SOL wallet, sponsored deposit and rollup setup.
  • Let your coding agent do the wiring: npx skills add magicblock-labs/magicblock-dev-skill installs the MagicBlock skill for Claude Code, Cursor, Codex and other agents. It covers delegation, VRF, Ephemeral Accounts and the Payments API.
  • Docs: docs.magicblock.gg