Telegram Mini App Development: How We Built SpyClub, a Multiplayer Game with 100,000+ Players
Telegram Mini App development means building three things that work together: a web app that Telegram opens inside a chat, a bot that launches it and messages users, and a back end that verifies who those users are. This guide shows how we built each part for SpyClub, a real-time multiplayer game that passed 100,000 players within weeks of launch and pays rewards on-chain. It covers the stack, the multiplayer logic, the bot setup, authentication, deployment, and what we would do again.
New to the format? Start with our overview of Telegram Mini Apps and the TON blockchain.
What is SpyClub?
SpyClub brings the word association board game Codenames to Telegram. Players join live matches and compete to guess words from one-word clues. The best players win $SPY tokens, which convert to USDC rewards.
Key features:
- Real-time multiplayer matches every 30 minutes
- A reward system combining in-game currency and a real token ($SpyCoin on the Hedera blockchain)
- Social features: referrals, leaderboards and Telegram bot messages
- Automated on-chain wallet creation, so players never handle a seed phrase
- A farming mechanism for passive earnings
- A progressive quest system to keep players engaged
What does a Telegram Mini App architecture look like?
A Mini App is a standard web application with two Telegram-specific pieces around it: the Mini App SDK in the front end and a bot on the server. Here is how SpyClub fits together.

Tech stack
Frontend
- Core: React with Vite and TypeScript
- State Management: Zustand for lightweight global state
- Styling: Tailwind CSS with shadcn/ui components
- Animations: Framer Motion for smooth transitions
- Real-time: Supabase Realtime for multiplayer features
- Platform Integration: Telegram Mini App SDK
- Deployment: CI/CD with GitHub + Vercel
Backend
- Server: Fastify for high-performance API handling
- Database: Supabase (PostgreSQL) for data persistence
- Real-time: Supabase Realtime for WebSocket management
- Storage: Supabase Storage for media files
- Type Safety: TypeScript throughout the stack
External integrations
Telegram
- User authentication via Telegram
- Mini App SDK for native features (haptic feedback for instance)
- Telegraf as Bot API framework for notifications and updates
To start faster, we published an open-source Telegram Mini App boilerplate with React and Vite on GitHub.
Blockchain
- Hedera blockchain for token transactions
- Daily USDC rewards distribution with CRON jobs
- Automated on-chain wallet creation for users
Analytics and monitoring
- User behavior tracking with MixPanel
- Performance monitoring with Google App Engine
- Error tracking and reporting with Sentry
How do you build real-time multiplayer in a Mini App?
Game rooms on the server
The server is the single source of truth. Each match runs in a game room that owns its players, the current round and the score, and advances on a fixed tick. Clients only send actions and render what the server broadcasts, which keeps every phone in sync and makes cheating harder. A simplified version of our room class:
export class GameRoom {
private players: Map<string, Player> = new Map()
private currentRound: Round | null = null
private scoreTracker: ScoreTracker
async startGame() {
if (this.players.size < MIN_PLAYERS) {
throw new Error('Not enough players')
}
this.currentRound = await this.initializeRound()
this.broadcastGameStart()
this.gameLoop = setInterval(() => {
this.updateGameState()
}, TICK_RATE)
}
private async updateGameState() {
if (this.shouldEndRound()) {
await this.endRound()
if (this.isGameComplete()) {
await this.endGame()
} else {
await this.startNextRound()
}
}
}
}Client state with Zustand
On the client, real-time updates arrive through Supabase Realtime and land in a single Zustand store. Components subscribe to the slice they need, so a score update does not re-render the whole board:
interface GameState {
room: GameRoom | null
currentRound: RoundData | null
players: Player[]
userScore: number
leaderboard: LeaderboardEntry[]
}
const useGameStore = create<GameState>((set) => ({
room: null,
currentRound: null,
players: [],
userScore: 0,
leaderboard: [],
updateGameState: (newState: Partial<GameState>) =>
set((state) => ({ ...state, ...newState })),
handleRoundEnd: async (roundResults) => {
set((state) => ({
...state,
userScore: state.userScore + roundResults.score,
leaderboard: roundResults.newLeaderboard
}))
}
}))How do you set up the Telegram bot?
Every Mini App belongs to a bot. The bot launches the app, receives commands and sends notifications. You create it by chatting with BotFather, Telegram's official bot for creating bots:
- Open Telegram and search for "@BotFather"
- Start a conversation with /newbot
- Follow the prompts to:
- Set your bot's display name
- Choose a unique username (must end in 'bot')
BotFather then gives you a Bot Token, the key to Telegram's Bot API. Treat it like a password and load it from an environment variable:
// From config.ts
export const BOT_TOKEN = process.env.BOT_TOKEN || ""
export const TELEGRAM_API_BASE_URL = "https://api.telegram.org"Then set up the bot commands on the server. We use Telegraf behind a Fastify route, so Telegram pushes updates to a webhook and the server does not need to poll:
import { FastifyInstance } from "fastify"
import { Telegraf, Context } from "telegraf"
import { BOT_TOKEN, BACKEND_URL, APP_URL, TELEGRAM_BOT_URL } from "../config"
export function setupBotCommands(fastify: FastifyInstance) {
const bot = new Telegraf(BOT_TOKEN)
bot.command("start", async (ctx: Context) => {
/** Your start command logic **/
})
// Set up webhook
fastify.post(`/bot${BOT_TOKEN}`, (request, reply) => {
bot.handleUpdate(request.body as any, reply.raw)
})
// Start the bot
bot.launch({
webhook: {
domain: `${BACKEND_URL}`,
hookPath: `/bot${BOT_TOKEN}`,
},
})
fastify.log.info("Bot commands set up successfully")
}
Finally, register the webhook URL with the Telegram Bot API:
curl --request POST 'https://api.telegram.org/bot{bot_token}/setWebhook' \ --data-urlencode 'url=https://your-backend.example.com/bot{bot_token}'
Check that it was registered correctly with:
curl --location 'https://api.telegram.org/bot{bot_token}/getWebhookInfo'
How do you authenticate Telegram Mini App users?
A Mini App has no login screen, so the server needs another way to know who is calling. When Telegram opens the app, it passes an initData string containing the user's ID and name, the launch time, and a hash signed with your bot token. The front end sends this string with every API request, and the server checks it before trusting anything:
- Parse
initDataand set thehashfield aside. - Sort the remaining
key=valuepairs alphabetically and join them with newlines. - Derive a secret key: HMAC-SHA256 of your bot token, keyed with the constant string
WebAppData. - Compute the HMAC-SHA256 of the joined string with that secret key, and compare it to
hash. - Reject the request if the hashes differ or if
auth_dateis too old.
Never read the user ID from initDataUnsafe on the server, or from a request parameter. Anyone can forge those. This check matters most in a game with real rewards, where a forged identity means stolen tokens.
How do you deploy and scale a Mini App back end?
Mini Apps grow through share links and referrals, so traffic arrives in spikes. SpyClub runs on Google App Engine, which adds instances automatically under load:
- Game rooms are distributed across multiple server instances
- Database queries are optimized with proper indexing
- Caching layers for frequently accessed data
- Load balancing for even distribution of player connections
Our app.yaml is short:
runtime: nodejs20
service: spyclub-backend-prod
automatic_scaling:
min_instances: 1
inbound_services:
- warmup
env_variables: your env here
What did we learn building SpyClub?
- Keep the server authoritative. Synchronizing game state across thousands of clients only works when one side decides. Clients send intentions, the server sends results.
- Make on-chain payouts retryable. Transactions fail and networks stall. Every reward distribution needs retries, idempotency and a log, so that a player is never paid twice or not at all.
- Hide the blockchain until it matters. Wallets are created automatically, so nobody has to install one or write down a seed phrase before their first match. The balance between game mechanics and blockchain features decides whether players stay.
- Design for phones first. Almost everyone plays inside the Telegram mobile app. Test on mid-range Android devices, keep bundles small, and use haptics where they add something.
- Plan for spikes. A single viral referral loop can multiply traffic in an hour. Autoscaling and proper database indexes are cheaper than an outage on launch day.
Frequently asked questions
What stack should I use for a Telegram Mini App?
Any web stack works. A common choice is React with Vite and TypeScript on the front end, the Telegram Mini Apps SDK for native features, a Node.js server such as Fastify, PostgreSQL for data, and a bot framework like Telegraf.
Do I need the TON blockchain to build a Telegram Mini App?
No. A Mini App can run without any blockchain. When you need tokens or rewards, TON is the usual choice because of its wallet integration, but SpyClub shows that another network, here Hedera, works when the app manages wallets for its users.
How much does it cost to build a Telegram Mini App?
It depends on scope: a simple app is a matter of weeks, while a multiplayer game with a token economy takes months. Our Web3 development cost calculator gives an itemized estimate.
Ready to build your own?
The architecture and patterns above are a solid starting point for a game, a DeFi tool or any other Mini App. The technical side is only half of it, though: the apps that last are the ones people enjoy coming back to.
We build Mini Apps end to end, from gameplay to token economy. See our Telegram Mini App development service and the SpyClub case study, or tell us about your project.


