<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Pavel AL</title>
    <description>The latest articles on DEV Community by Pavel AL (@paulbreaks).</description>
    <link>https://dev.to/paulbreaks</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4260313%2Fe261528d-2c79-4fb7-9c48-bb271eb03dff.jpg</url>
      <title>DEV Community: Pavel AL</title>
      <link>https://dev.to/paulbreaks</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/paulbreaks"/>
    <language>en</language>
    <item>
      <title>How I Built a Mobile Game with TON Payments</title>
      <dc:creator>Pavel AL</dc:creator>
      <pubDate>Tue, 24 Nov 2026 16:17:59 +0000</pubDate>
      <link>https://dev.to/paulbreaks/how-i-built-a-mobile-game-with-ton-payments-59gf</link>
      <guid>https://dev.to/paulbreaks/how-i-built-a-mobile-game-with-ton-payments-59gf</guid>
      <description>&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://crazycash.app/" rel="noopener noreferrer"&gt;&lt;u&gt;Try FUN mode&lt;/u&gt;&lt;/a&gt; · &lt;a href="https://github.com/Paulbreaks/crazycash-app" rel="noopener noreferrer"&gt;&lt;u&gt;Source code&lt;/u&gt;&lt;/a&gt; · &lt;a href="https://crazycash.app/dev" rel="noopener noreferrer"&gt;&lt;u&gt;RTP lab&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  A little background
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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 :-)&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Where the idea came from
&lt;/h2&gt;

&lt;p&gt;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 :-)&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8ipor6zeb041gypsm2ce.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8ipor6zeb041gypsm2ce.jpg" alt="A woman playing a coin-operated slot machine in a small Eastern European grocery store" width="800" height="603"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;All right, let's get into it!&lt;/p&gt;

&lt;h2&gt;
  
  
  The stack and project structure
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6joxnk8qhmi24n9i9rei.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6joxnk8qhmi24n9i9rei.jpg" alt="Tools and Technology Stack" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Godot 4 and GDScript.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;React, TypeScript, and Vite.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Node.js and Fastify.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MySQL and Prisma.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;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!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Photoshop and Docker Compose.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Telegram and TON.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Everything lives in a &lt;a href="https://github.com/Paulbreaks/crazycash-app" rel="noopener noreferrer"&gt;monorepo&lt;/a&gt;, with a directory for each part:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apps/
├── godot/             # Godot game
│   ├── scenes/        # Scenes and game UI structure
│   ├── scripts/       # GDScript: behavior and interactions
│   ├── assets/        # Graphics, audio, fonts, and other resources
│   ├── data/          # Game data
│   └── web/           # Web build loading template
├── web/               # React and TypeScript shell
└── api/               # Fastify backend and Prisma schema and migrations

packages/
└── shared/            # Shared types and contracts

docker/                # Containers and environment configuration
scripts/               # Helper scripts
docs/                  # Project documentation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;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 &lt;code&gt;postMessage&lt;/code&gt;, 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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Design and familiar sounds
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ft01qzhkcg0xswtl85siq.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ft01qzhkcg0xswtl85siq.jpg" alt="Creating a design in Photoshop" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;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 :-)&lt;/p&gt;

&lt;p&gt;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 :-)&lt;/p&gt;

&lt;h2&gt;
  
  
  The math and the RTP lab
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdh6h8w6b0u9cb0lmd942.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdh6h8w6b0u9cb0lmd942.jpg" alt="Paytable" width="800" height="512"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Before assembling the game, I worked on the backend math and built an &lt;a href="https://crazycash.app/dev" rel="noopener noreferrer"&gt;RTP lab&lt;/a&gt;. 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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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%.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;That's pretty generous by gambling industry standards. For comparison, single-zero European roulette has an RTP of about 97.3%.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can try the result in &lt;a href="https://crazycash.app/" rel="noopener noreferrer"&gt;FUN mode&lt;/a&gt; and check out the weights and calculations in the &lt;a href="https://github.com/Paulbreaks/crazycash-app/blob/main/apps/api/src/modules/slot777/engine.ts" rel="noopener noreferrer"&gt;server-side engine&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Godot and its connection to Shell
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpdbvc0edjmemy83c2ex4.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpdbvc0edjmemy83c2ex4.jpg" alt="Godot editor" width="800" height="537"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Client logic is split across GDScript files attached to nodes. The main &lt;code&gt;slots.gd&lt;/code&gt; switches game states and makes sure the reels, sounds, and effects fire at the right time.&lt;/p&gt;

&lt;p&gt;A separate &lt;code&gt;web_bridge.gd&lt;/code&gt; 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.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;postMessage&lt;/code&gt; contract uses messages with type and payload fields. When the player hits PLAY, the game sends &lt;code&gt;game:spinRequested&lt;/code&gt; with the bet and mode. Shell validates the message, calls the API, and returns &lt;code&gt;shell:spinResult&lt;/code&gt; with the combination, payout, and balance, or &lt;code&gt;shell:spinError&lt;/code&gt;. All messages are documented in &lt;a href="https://github.com/Paulbreaks/crazycash-app/blob/main/docs/GODOT.md" rel="noopener noreferrer"&gt;docs/GODOT.md&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The API and the game balance
&lt;/h2&gt;

&lt;p&gt;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 money into the game: the wallet balance and the in-game REAL balance are separate things.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sessions and round processing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;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 &lt;code&gt;initData&lt;/code&gt;, 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.&lt;/p&gt;

&lt;p&gt;When the player hits PLAY, Shell sends &lt;code&gt;POST /crazy-cash/spins&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;  
&lt;span class="nl"&gt;"mode"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"fun"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;  
&lt;span class="nl"&gt;"bet"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"10"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;  
&lt;span class="nl"&gt;"requestId"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"unique-request-identifier"&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When the response gets lost&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;That's why Shell creates a &lt;code&gt;requestId&lt;/code&gt; 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 &lt;code&gt;GET /crazy-cash/spins/by-request&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Deposits, withdrawals, and FUN credit claims use a similar mechanism: their own identifier and a saved state in &lt;code&gt;client_operations&lt;/code&gt;. A timeout doesn't mean cancellation. First, find out what happened to the original operation. Request and error formats are in &lt;a href="https://github.com/Paulbreaks/crazycash-app/blob/main/docs/API.md" rel="noopener noreferrer"&gt;docs/API.md&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What goes into the database&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;MySQL stores users, sessions, wallets, rounds, and financial operations. FUN and REAL balances are separate, as are the &lt;code&gt;fun_spins&lt;/code&gt; and &lt;code&gt;real_spins&lt;/code&gt; tables. Each round records the bet, combination, rule, multiplier, payout, and balance after processing.&lt;/p&gt;

&lt;p&gt;I store amounts as integers: &lt;strong&gt;1 GRAM = 1,000 internal units&lt;/strong&gt;. 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 :-)&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;For REAL, there's a &lt;code&gt;ledger_entries&lt;/code&gt; 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 &lt;code&gt;deposits&lt;/code&gt; and &lt;code&gt;withdrawals&lt;/code&gt;: an API request and a blockchain transfer aren't one MySQL transaction, so every stage has to survive a restart.&lt;/p&gt;

&lt;p&gt;The details are in &lt;a href="https://github.com/Paulbreaks/crazycash-app/blob/main/docs/DATABASE.md" rel="noopener noreferrer"&gt;docs/DATABASE.md&lt;/a&gt;, and the schema itself is in &lt;a href="https://github.com/Paulbreaks/crazycash-app/blob/main/apps/api/prisma/schema.prisma" rel="noopener noreferrer"&gt;schema.prisma&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Telegram and TON — now for the interesting part
&lt;/h2&gt;

&lt;p&gt;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 money the service owes the user.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Turning the game into a Mini App&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Create a bot through &lt;a href="https://t.me/BotFather" rel="noopener noreferrer"&gt;@BotFather&lt;/a&gt;, then set the game's public HTTPS URL in the Main Mini App settings. Mine is &lt;code&gt;https://crazycash.app/game&lt;/code&gt;. After that, users can open it from the bot's profile or a link with &lt;code&gt;?startapp&lt;/code&gt;. Here's the bot &lt;a href="https://core.telegram.org/bots/features#creating-a-new-bot" rel="noopener noreferrer"&gt;creation guide&lt;/a&gt; and &lt;a href="https://core.telegram.org/bots/webapps" rel="noopener noreferrer"&gt;Mini Apps documentation&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  TON Connect and the manifest
&lt;/h2&gt;

&lt;p&gt;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.&lt;br&gt;
Shell uses &lt;code&gt;@tonconnect/ui-react&lt;/code&gt; for the provider, wallet selection UI, and wallet interaction methods. Connecting requires a public JSON manifest:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;  
&lt;span class="nl"&gt;"url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://game.example"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;  
&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Crazy Cash"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;  
&lt;span class="nl"&gt;"iconUrl"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://game.example/tonconnect-icon.png"&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The wallet reads the file and displays the application's name and icon. The &lt;a href="https://github.com/Paulbreaks/crazycash-app/blob/main/apps/web/public/tonconnect-manifest.json" rel="noopener noreferrer"&gt;template&lt;/a&gt; in the repository is served at the URL specified by &lt;code&gt;VITE_TON_MANIFEST_URL&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;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 &lt;a href="https://docs.ton.org/applications/ton-connect/get-started" rel="noopener noreferrer"&gt;TON Connect guide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;An address doesn't prove ownership&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A wallet address is public. A client sending it to the API doesn't prove the user controls it. That's what &lt;code&gt;ton_proof&lt;/code&gt; is for.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;After verification, the association between the user, wallet, and network is saved. Telegram authentication answers “who opened the game,” while &lt;code&gt;ton_proof&lt;/code&gt; answers “which wallet they control.” This doesn't move money or create a separate paid transaction.&lt;/p&gt;

&lt;p&gt;Verification currently supports V4 and V5R1 wallets. Compatibility with TON Connect alone doesn't mean the server supports every wallet contract. Details are in &lt;a href="https://github.com/Paulbreaks/crazycash-app/blob/main/docs/TON.md" rel="noopener noreferrer"&gt;docs/TON.md&lt;/a&gt; and the &lt;a href="https://docs.ton.org/applications/ton-connect/how-to/ton-proof" rel="noopener noreferrer"&gt;ton_proof documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RPC and network selection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;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 &lt;a href="https://toncenter.com/" rel="noopener noreferrer"&gt;TON Center&lt;/a&gt; and its JSON-RPC API v2.&lt;/p&gt;

&lt;p&gt;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 &lt;a href="https://github.com/Paulbreaks/crazycash-app/blob/main/docs/CONFIGURATION.md" rel="noopener noreferrer"&gt;docs/CONFIGURATION.md&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The network is selected through &lt;code&gt;TON_NETWORK: testnet&lt;/code&gt; for testing, &lt;code&gt;mainnet&lt;/code&gt; for real funds. Their balances and histories are independent. For testing, you can get coins through the &lt;a href="https://docs.ton.org/onboarding/wallet-apps/get-coins" rel="noopener noreferrer"&gt;faucet linked in the documentation&lt;/a&gt;. You don't have to switch Telegram itself to a test environment.&lt;/p&gt;

&lt;p&gt;The RPC endpoint, connected wallet, deposit address, and payout wallet must all match the selected network. Money operations have separate enable flags: changing &lt;code&gt;TON_NETWORK&lt;/code&gt; alone isn't enough.&lt;/p&gt;

&lt;h2&gt;
  
  
  How GRAM gets into the game and back out
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Deposits&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Shell sends the amount and &lt;code&gt;operationId&lt;/code&gt; to &lt;code&gt;POST /deposits&lt;/code&gt;. The API creates an invoice with an expiration time and returns the address, the exact amount in nanotons, and a payload containing the &lt;code&gt;CC:D:&amp;lt;uuid&amp;gt;&lt;/code&gt; comment. Shell passes the data to TON Connect, and the user confirms the transfer.&lt;/p&gt;

&lt;p&gt;But a successful wallet response isn't a reason to increase the balance yet. Verification is handled by the &lt;strong&gt;deposit watcher&lt;/strong&gt;, 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.&lt;/p&gt;

&lt;p&gt;A matching payment gets the &lt;code&gt;observed&lt;/code&gt; 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 &lt;code&gt;credited&lt;/code&gt;, and increases the REAL balance, all in one MySQL transaction.&lt;/p&gt;

&lt;p&gt;Meanwhile, Shell polls the API. Closing the interface doesn't stop verification, and the operation ID is saved in &lt;code&gt;sessionStorage&lt;/code&gt; so waiting can resume after a reload within the same browser session.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Withdrawals&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Shell sends the amount and &lt;code&gt;operationId&lt;/code&gt; to &lt;code&gt;POST /withdrawals&lt;/code&gt;. It doesn't send a destination address: the server gets that from the active wallet association verified through &lt;code&gt;ton_proof&lt;/code&gt;. You can't just slip someone else's address into the request.&lt;/p&gt;

&lt;p&gt;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 &lt;strong&gt;payout worker&lt;/strong&gt; handles that.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;The worker checks the wallet and the funds available for fees, signs a message with the comment &lt;code&gt;CC:W:&amp;lt;uuid&amp;gt;&lt;/code&gt;, and submits it through RPC. It then looks for confirmation on the recipient's side. The operation states look like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;held → requested → sent → finalized&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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 money 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.&lt;/p&gt;

&lt;p&gt;State transitions and checks are documented in &lt;a href="https://github.com/Paulbreaks/crazycash-app/blob/main/docs/PAYMENTS.md" rel="noopener noreferrer"&gt;docs/PAYMENTS.md&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;One successful transfer isn't enough&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  A quick start for dev and prod
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Locally, you'll need Docker with Compose, Node.js 26, and pnpm 10.33.2. After cloning the repository, run this from its root:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cp .env.dev.example .env.dev 
pnpm install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fill in the required &lt;code&gt;CHANGE_ME&lt;/code&gt; values in &lt;code&gt;.env.dev&lt;/code&gt; using the &lt;a href="https://github.com/Paulbreaks/crazycash-app/blob/main/docs/CONFIGURATION.md" rel="noopener noreferrer"&gt;configuration guide&lt;/a&gt;, then run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pnpm docker:dev:up
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The game is at &lt;code&gt;http://localhost:&amp;lt;WEB_PORT&amp;gt;/game&lt;/code&gt;, and the lab is at &lt;code&gt;/dev&lt;/code&gt;. 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 &lt;code&gt;ton-payout&lt;/code&gt; profile and its corresponding flag.&lt;/p&gt;

&lt;p&gt;You only need Godot 4.7.1 if you're changing the game: export the web build to &lt;code&gt;apps/web/public/godot&lt;/code&gt; and run &lt;code&gt;./scripts/compress-godot-web-build.sh&lt;/code&gt;. Details are in &lt;a href="https://github.com/Paulbreaks/crazycash-app/blob/main/docs/QUICKSTART.md" rel="noopener noreferrer"&gt;QUICKSTART&lt;/a&gt; and the &lt;a href="https://github.com/Paulbreaks/crazycash-app/blob/main/docs/GODOT.md" rel="noopener noreferrer"&gt;Godot guide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For prod, you'll need a server, Docker Compose, a domain, and HTTPS. An external reverse proxy forwards requests to the web container at &lt;code&gt;127.0.0.1:20069&lt;/code&gt;; /api is then routed to the backend. Create &lt;code&gt;.env.prod&lt;/code&gt; from &lt;code&gt;.env.prod.example&lt;/code&gt; and set the public URLs and secrets. Keep the mnemonic out of Git and give the payout worker access to it.&lt;/p&gt;

&lt;p&gt;Before launching, check the project and build the containers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pnpm typecheck 
pnpm test 
pnpm build 
docker compose --env-file .env.prod -f docker/compose.prod.yml up -d --build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Prod doesn't mean mainnet: you can run everything on testnet first. After launch, check &lt;code&gt;/api/health&lt;/code&gt; and the worker logs, and set up MySQL backups separately. They aren't automatic here. Update and troubleshooting details are in &lt;a href="https://github.com/Paulbreaks/crazycash-app/blob/main/docs/OPERATIONS.md" rel="noopener noreferrer"&gt;docs/OPERATIONS.md&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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 &lt;a href="https://phaser.io/" rel="noopener noreferrer"&gt;Phaser&lt;/a&gt; or &lt;a href="https://pixijs.com/" rel="noopener noreferrer"&gt;PixiJS&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;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 :-)&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;AI also helped with drafting and editing the text, as well as some of the illustrations. The project itself and the development experience described here are my own.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Paulbreaks/crazycash-app" rel="noopener noreferrer"&gt;The source is open&lt;/a&gt;, and &lt;a href="https://crazycash.app/" rel="noopener noreferrer"&gt;FUN mode is available&lt;/a&gt;. If you find bugs or have suggestions for improvements, I'd love to hear them.&lt;/p&gt;

&lt;h2&gt;
  
  
  One last thing
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;So I'm looking ahead with optimism! Feel free to &lt;a href="https://t.me/jetnc" rel="noopener noreferrer"&gt;reach out to me on Telegram&lt;/a&gt;, and you can see some of my work on &lt;a href="https://dribbble.com/pavelal" rel="noopener noreferrer"&gt;Dribbble&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Okay, now I'm really done :-)&lt;/p&gt;

</description>
      <category>web3</category>
      <category>gamedev</category>
      <category>mobile</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
