I built Crazy Cash, a mobile browser-based 2D game made with Godot, a React web shell, a Node.js backend, and payments through TON. It runs in a browser and as a Telegram Mini App. Here's how I put it all together, from the initial idea to processing rounds, deposits, and payouts.
Try FUN mode · Source code and documentation · RTP lab
A little background
The past few years have been a turning point for me. In 2023, I got into blockchain development, then started a company, went through a serious financial crisis, and started over. I can't say I'm fully back on my feet yet, but I've picked up a lot of experience along the way.
At some point, I got tired of freelancing: repetitive tasks, other people's code, and wondering whether there would be work tomorrow. So I decided to build something different, show what I can do, dust off my 2D game development skills, and combine them with what I've learned over the past few years. Who knows, maybe something will come of it :-)
A quick heads-up: I won't be covering programming basics or walking through every line of code. The focus is on the concept and architecture. You can dig through the repository for the details.
I'm also not promoting gambling in any way. The slot game is a practical demonstration of monetizing a Mini App through TON. It could have been any other game, but given my background, this was the format I went with.
Where the idea came from
I got my start in tech through online gambling. In the early 2010s, I was learning to build browser-based video slots with PHP, MySQL, and Flash. The server calculated winnings, the database stored users and balances, and Flash handled the visuals. Shout-out to the old-timers :-)
We made everything from simple single-payline slots to more complex games with 21 paylines and bonus rounds. Honestly, most were clunky copies of physical slot machines: we'd pull graphics and sounds from their boards, cut up sprites, and put together a browser version. That approach would raise plenty of eyebrows today, but back then, everyone worked with what they knew.

I'd actually seen my first slot machine much earlier, in a grocery store in the early 2000s. There was a small pillar-shaped machine near the entrance, with a woman feeding five-ruble coins into it. Each playable side had three red LED digits, a paytable, a coin slot, and a metal tray. Not a single button. Drop in a coin, watch the digits spin, and if you win, coins come clattering into the tray.
At first, I'd just walk past with a goofy grin. Then I tried it myself, got a couple of small wins, and understood the appeal: one coin, three seconds, a result. Those little machines eventually disappeared, but the game stuck with me. About 20 years later, I wanted to bring it to a mobile browser and connect it to Telegram.
All right, let's get into it!
The stack and project structure
I didn't want to get too adventurous with the stack. It's a small project, and I don't see the point in complicating it just for a trendy architecture.

Godot 4 and GDScript. Honestly, I chose the engine to get some practice: I'd never worked with it before. It's free and has a handy visual editor. Along the way, I realized it wasn't the best fit for a mobile WebView, but I'll get to that at the end.
React, TypeScript, and Vite. The game sits inside Shell, a web wrapper. It embeds Godot in an iframe and connects it to the API, Telegram, and the wallet. React works well for the UI, TypeScript helps keep data structures in check, and Vite handles development and builds.
Node.js and Fastify. A familiar stack for my API. The server validates bets, selects outcomes, and updates balances. You can't trust the client with that: its code can be modified, and requests can be sent straight to the API.
MySQL and Prisma. I've worked with MySQL for a long time, and I use Prisma to define the schema and migrations. PostgreSQL would have been fine too, but there are no special requirements here. Good old phpMyAdmin helps me take a quick look at the data, in dev only!
Photoshop and Docker Compose. I create the graphics in Photoshop because I'm used to it. Besides, I've already paid for a year's subscription :-) Docker Compose runs the web client, API, workers, and database. Not much to explain here. Pretty standard stuff.
Telegram and TON. Users open the Mini App right inside the messenger and connect their wallets through TON Connect. That connection to the Telegram ecosystem is what drew me to TON: the game and payments in one place, without extra hassle.
Everything lives in a monorepo, with a directory for each part:
apps/godot/ # Scenes, GDScript, graphics, and audio apps/web/ # React Shell and integrations apps/api/ # API, Prisma, and background jobs packages/shared/ # Space for shared types and contracts src/ # Archives of PSDs, WAVs, and fonts docker/ # Containers and environment setup scripts/ # Helper scripts docs/ # Documentation That keeps everything close at hand, and changes across related components can go into a single commit. The overall flow is simple: Godot exchanges events with Shell through postMessage, Shell calls the API, and the server calculates the result and saves it in MySQL. Wallet connections go through TON Connect; payment verification stays on the backend.
Design and familiar sounds
As usual, the visuals started with a picture in my head. I sketched it on paper first, then moved over to my trusty Photoshop.

I'd had the Crazy Cash logo in vector form for years. Around 2015, I redrew it from a photo of a slot machine parlor near my home in my hometown. I meant to use it for another online project but never got around to it. That's where the blue background and overall visual style came from.
The frames, paytables, LED display, and illuminated logo and buttons took some wrestling. After a week or two of experimenting, I had a finished concept, which I split into sprites for Godot. I think it turned out pretty well :-)
The audio was a funnier story. A few hours browsing free sound libraries got me nowhere. Then I remembered the old Flash slots that had been sitting in my archives for over 15 years. I dusted off a dozen or two SWF files, decompiled them, pulled out those familiar sounds, and processed them in Ableton Live. If you remember the old video slots, you might get a little hit of nostalgia :-)
The math and the RTP lab
The paytable isn't just part of the design. Together with the probabilities of the combinations, it determines RTP, or Return to Player: the theoretical percentage of total wagers returned to players over the long run.
I didn't remember the old machines' paytables by heart, so I went looking for archived photos. I started with the familiar 0XX, 00X, 7XX, 77X, three matching digits, and, of course, 777 paying 200 times the bet. When rules overlap, the highest multiplier applies: 777 pays ×200, not ×10 or ×2.
Before assembling the game, I worked on the backend math and built an RTP lab. You can adjust the weights and see the calculated RTP alongside simulation results. Each group of outcomes gets a weight: the larger it is relative to the others, the more often that group comes up. RTP is the sum of each probability multiplied by its payout multiplier.
You can get the same RTP with frequent small wins or rare big ones. So the final percentage alone doesn't tell the whole story.
In the first version, each three-of-a-kind combination had a probability of about 0.087%. That applied to both 000 at ×15 and 777 at ×200. Pretty crude, right? The calculated RTP was 98.46%, but 777 contributed roughly 13 times as much as 000. Players would mostly see losses and small payouts, and a big win might never show up during a short session.
I kept tweaking the weights, making triples with smaller multipliers more likely and reducing the chances of 555 and 777. That was the trade-off needed to make the game feel more active while keeping the target RTP at 98–99%.
That's pretty generous by gambling industry standards. For comparison, single-zero European roulette has an RTP of about 97.3%.
You can try the result in FUN mode and check out the weights and calculations in the server-side engine.
Godot and its connection to Shell
In Godot, a game is built from nodes and scenes. A node displays a sprite, plays a sound, or handles a button, and scenes can be nested inside other scenes, a bit like nesting dolls. I create separate scenes for the reels, scrolling text, or a button, then combine them into the main interface.

Client logic is split across GDScript files attached to nodes. The main slots.gd switches game states and makes sure the reels, sounds, and effects fire at the right time.
A separate web_bridge.gd passes player actions to Shell. The wrapper calls the API and sends responses back to Godot. The game itself doesn't make HTTP requests or decide how much you've won. Its job is to make the server's result look good.
The postMessage contract uses messages with type and payload fields. When the player hits PLAY, the game sends game:spinRequested with the bet and mode. Shell validates the message, calls the API, and returns shell:spinResult with the combination, payout, and balance, or shell:spinError. All messages are documented in docs/GODOT.md.
The API and the game balance
A regular browser gives you free FUN mode. In Telegram, you can play with either virtual credits or GRAM. Deposits and withdrawals require a connected wallet with verified ownership. Connecting a wallet doesn't move crypto-tokens into the game: the wallet balance and the in-game REAL balance are separate things.
For browser users, the server creates a temporary guest user; a background worker deletes it after 24 hours of inactivity. When the game launches through Telegram, Shell passes initData, the backend verifies the signature, and it creates a session for a persistent user identified by their Telegram ID. The session is stored in an HttpOnly cookie handled by the wrapper, not Godot.
When the player hits PLAY, Shell sends POST /crazy-cash/spins:
{ "mode": "fun", "bet": "10", "requestId": "unique-request-identifier" } The server validates the session, bet, and balance, selects a weighted outcome, calculates the payout, and saves the round. Shell receives the combination, multiplier, winnings, and new balance, then passes them to Godot. By the time the reels start revealing the result, the server has already determined it.
Checking the balance, deducting the bet, crediting winnings, and saving the result all happen in one transaction with a lock on the user's row. Either all changes commit together or they roll back. Hello, fintech :-) Two concurrent requests can't independently spend the same remaining balance.
When the response gets lost
Sometimes mobile internet decides to take a break: the bet has been processed, but the response never arrives. Simply sending a new request risks starting a second round.
That's why Shell creates a requestId for each spin. A retry with the same identifier and parameters returns the saved result; the server rejects different parameters under the same ID. That's idempotency. A lost response can be recovered through GET /crazy-cash/spins/by-request.
Deposits, withdrawals, and FUN credit claims use a similar mechanism: their own identifier and a saved state in client_operations. A timeout doesn't mean cancellation. First, find out what happened to the original operation. Request and error formats are in docs/API.md.
What goes into the database
MySQL stores users, sessions, wallets, rounds, and financial operations. FUN and REAL balances are separate, as are the fun_spins and real_spins tables. Each round records the bet, combination, rule, multiplier, payout, and balance after processing.
I store amounts as integers: 1 GRAM = 1,000 internal units. Why that scale? The minimum bet of 0.01 GRAM becomes 10 credits. For the smallest nonzero payout, an animation of ten coins falling into a tray looks more natural than crediting a single unit. Purely an aesthetic choice :-)
When interacting with the blockchain, amounts are converted to nanotons. In JSON, they're sent as strings so JavaScript doesn't lose precision with large integers. There's no need for floating-point arithmetic in balance calculations.
For REAL, there's a ledger_entries journal for deposits, bets, winnings, funds placed on hold, and funds returned. A single “current balance” number isn't enough. You need to know which operations produced it. Deposits and withdrawals live separately in deposits and withdrawals: an API request and a blockchain transfer aren't one MySQL transaction, so every stage has to survive a restart.
The details are in docs/DATABASE.md, and the schema itself is in schema.prisma.
Telegram and TON — now for the interesting part
In Crazy Cash, the blockchain handles deposits and payouts. Spins and winnings are calculated on the server, and the game balance lives in MySQL. That means you don't have to confirm every round in your wallet or pay for every spin. The user deposits funds, plays, then requests a withdrawal. The game balance represents crypto-tokens the service owes the user.
By the way, you'll see GRAM in the article and the interface, while the code still uses TON_* and nanotons. That's because the native coin was recently renamed from Toncoin to Gram. We're talking about the same coin here, not a custom Jetton issued by the project.
Turning the game into a Mini App
A Mini App is a regular web application running inside Telegram's built-in WebView. In my case, it loads the React Shell, with the Godot web build inside it. Telegram provides the environment, but the site and API are hosted on my server.
Create a bot through @BotFather, then set the game's public HTTPS URL in the Main Mini App settings. Mine is https://crazycash.app/game. After that, users can open it from the bot's profile or a link with ?startapp. Here's my bot, along with the bot creation guide and Mini Apps documentation.
At launch, Telegram passes initData. The server checks the authenticity and age of the original string. You can't just take a Telegram ID from the browser and trust it: client-side data can be tampered with.
TON Connect and the manifest
TON Connect connects the application to a wallet. It lets you get the address, request proof of ownership, and ask the user to sign a transaction. The user's private keys stay in the wallet.
Shell uses @tonconnect/ui-react for the provider, wallet selection UI, and wallet interaction methods. Connecting requires a public JSON manifest:
{ "url": "https://game.example", "name": "Crazy Cash", "iconUrl": "https://game.example/tonconnect-icon.png" } The wallet reads the file and displays the application's name and icon. The template in the repository is served at the URL specified by VITE_TON_MANIFEST_URL.
The manifest and icon must be publicly accessible: authentication, CORS, or a security challenge page can break the connection. The manifest itself doesn't guarantee that the application is safe. It only describes it. The requirements are in the TON Connect guide.
An address doesn't prove ownership
A wallet address is public. A client sending it to the API doesn't prove the user controls it. That's what ton_proof is for.
Shell gets a one-time challenge from the API, passes it to the wallet through TON Connect, and sends the signed response to the server. The backend checks the signature, domain, timestamp, network, and whether the key matches the address. The challenge is tied to the session, expires, and can only be used once.
After verification, the association between the user, wallet, and network is saved. Telegram authentication answers “who opened the game,” while ton_proof answers “which wallet they control.” This doesn't move crypto-tokens or create a separate paid transaction.
Verification currently supports V4 and V5R1 wallets. Compatibility with TON Connect alone doesn't mean the server supports every wallet contract. Details are in docs/TON.md and the ton_proof documentation.
RPC and network selection
TON Connect talks to the user's wallet. The server needs an independent way to check an address's state, read transfers, and submit a signed message. For that, I use TON Center and its JSON-RPC API v2.
The TON Center API key gives access to the service and its rate limits. It doesn't sign transfers. A public address is enough to monitor incoming payments; making a payout requires the service wallet's key. Endpoints, variables, and secret storage are documented in docs/CONFIGURATION.md.
The network is selected through TON_NETWORK: testnet for testing, mainnet for real funds. Their balances and histories are independent. For testing, you can get coins through the faucet linked in the documentation. You don't have to switch Telegram itself to a test environment.
The RPC endpoint, connected wallet, deposit address, and payout wallet must all match the selected network. Crypto-tokens operations have separate enable flags: changing TON_NETWORK alone isn't enough.
How crypto-tokens gets into the game and back out
Deposits
Deposits use a shared project wallet address, while each invoice gets a unique identifier, much like an invoice number in traditional fintech. It's included in the payment comment and ties the transfer to a database record.
Shell sends the amount and operationId to POST /deposits. The API creates an invoice with an expiration time and returns the address, the exact amount in nanotons, and a payload containing the CC:D:<uuid> comment. Shell passes the data to TON Connect, and the user confirms the transfer.
But a successful wallet response isn't a reason to increase the balance yet. Verification is handled by the deposit watcher, a separate process running in Docker. It reads the recipient's history through RPC and matches the sender, destination address, amount, comment, time, and operation success.
A matching payment gets the observed status: the transfer has been found but hasn't been credited yet. After a configured delay and another check through RPC, the worker records the deposit in the ledger, changes the status to credited, and increases the REAL balance, all in one MySQL transaction.
Meanwhile, Shell polls the API. Closing the interface doesn't stop verification, and the operation ID is saved in sessionStorage so waiting can resume after a reload within the same browser session.
Withdrawals
Shell sends the amount and operationId to POST /withdrawals. It doesn't send a destination address: the server gets that from the active wallet association verified through ton_proof. You can't just slip someone else's address into the request.
The API checks the balance, places the amount on hold, and creates a withdrawal record. The available balance decreases immediately, but the HTTP handler doesn't sign the transfer. A separate payout worker handles that.
The worker needs the service wallet's key. In my setup, it's derived from a mnemonic stored in a protected file on the server, outside the repository. Technically, deposits and payouts could use the same wallet, but I wouldn't do that: monitoring deposits doesn't require a key, and you can limit the funds kept in the payout wallet.
The worker checks the wallet and the funds available for fees, signs a message with the comment CC:W:<uuid>, and submits it through RPC. It then looks for confirmation on the recipient's side. The operation states look like this:
held → requested → sent → finalized In other words: funds are on hold, the worker has accepted the request, submission has been attempted, and receipt has been confirmed. Once it's complete, there's no need to deduct the amount again.
The nastiest case is when a transfer may have reached the network, but the process didn't get a response or restarted. You can't blindly retry the payout: the user could receive it twice. You can't immediately release the hold either, because the crypto-tokens may have arrived. First, check the blockchain. If it's confirmed that the failure happened before submission, release the held amount with a separate ledger entry.
State transitions and checks are documented in docs/PAYMENTS.md.
One successful transfer isn't enough
Beyond “deposit, play, withdraw,” you need to test wallet cancellation, the wrong network, duplicate commands, insufficient funds for fees, RPC downtime, and a worker restart after submission. For diagnostics, compare database records with transactions in an explorer, checking the result at the recipient, not just whether something was sent.
The current implementation has a limit: payout reconciliation reads a limited number of recent transactions without pagination. As traffic grows, it will need pagination or a saved processing position. Integration checks against real RPC services and MySQL also need a separate test suite. These limitations are documented.
A quick start for dev and prod
If you've made it this far, you might want to try the game, poke around the code, or look for vulnerabilities. I won't drag out the setup walkthrough. Here's what matters.
Locally, you'll need Docker with Compose, Node.js 26, and pnpm 10.33.2. After cloning the repository, run this from its root:
cp .env.dev.example .env.dev pnpm install Fill in the required CHANGE_ME values in .env.dev using the configuration guide, then run:
pnpm docker:dev:up The game is at http://localhost:<WEB_PORT>/game, and the lab is at /dev. Telegram and TON Connect need a publicly accessible HTTPS URL, for example through a tunnel. Test payments on testnet; the local payout worker is enabled separately through the ton-payout profile and its corresponding flag.
You only need Godot 4.7.1 if you're changing the game: export the web build to apps/web/public/godot and run ./scripts/compress-godot-web-build.sh. Details are in QUICKSTART and the Godot guide.
For prod, you'll need a server, Docker Compose, a domain, and HTTPS. An external reverse proxy forwards requests to the web container at 127.0.0.1:20069; /api is then routed to the backend. Create .env.prod from .env.prod.example and set the public URLs and secrets. Keep the mnemonic out of Git and give the payout worker access to it.
Before launching, check the project and build the containers:
pnpm typecheck pnpm test pnpm build docker compose --env-file .env.prod -f docker/compose.prod.yml up -d --build Prod doesn't mean mainnet: you can run everything on testnet first. After launch, check /api/health and the worker logs, and set up MySQL backups separately. They aren't automatic here. Update and troubleshooting details are in docs/OPERATIONS.md.
Wrapping up
The game took about four months, working only in my spare time. I enjoyed the process and I'm happy with the result. But it wasn't all smooth sailing.
The main issue was Godot. For all its strengths, it wasn't the best fit for my mobile WebView. In my case, the compressed build is around 10 MB, while the assets themselves are about 1 MB. For future projects, I'm already looking at Phaser or PixiJS.
The keyboard also took some wrestling. On iPhone, the Godot input field wouldn't bring it up, so I moved input into Shell. But instead of a numeric keyboard for decimal amounts, it opened the alphabetic one. You can switch manually. A small thing, sure, but annoying. By the time these rough edges became obvious, most of the game was already built. I didn't feel like rebuilding everything, but at least I've learned something new :-)
Next on the list is an admin panel for managing the game, viewing stats, and handling user operations. I'd also like my own blockchain transaction “streamer” instead of periodic RPC polling. That alone won't make the system more reliable, though: it still needs crash recovery, gap handling, and duplicate protection. There's work to do here.
I also used AI tools for coding, finding bugs, and reviewing solutions. I work with Codex and am putting together a collection of skills: instructions and reference materials for different tasks. I made a dedicated TON skill for this project. I still have to check the math and understand the code myself, but there's noticeably less grunt work.
The source is open, and FUN mode is available. If you find bugs or have suggestions for improvements, I'd love to hear them.
One last thing
I'm still working my way out of a financial crisis and figuring out what comes next. If the kind of work I do resonates with you and you need a developer or a partner, I'd be happy to talk about one-off projects or a longer-term collaboration.
Eventually, I'd like to build my own studio making small mobile Web3 games monetized through crypto-tokens. I think that combination has a lot of potential: no traditional payment systems or bank-based card processing. I think the advantages of crypto in this context are already pretty clear, especially in today's challenging times.
So I'm looking ahead with optimism! Feel free to reach out to me on Telegram, and you can see some of my work on Dribbble.
Okay, now I'm really done :-)
