Quick summary
This page shows how to run your Unity WebGL or web-based game inside Telegram Mini-Apps (Web Apps) and use the same Gx402 / x402 payment verification pattern:create → sign → confirm → finalize. Telegram Mini-Apps expose a JavaScript SDK (window.TelegramWebApp) for launch data, lifecycle, and UI primitives; Telegram also supports Bot Payments (invoices) for fiat flows and can host Web3/Unity WebGL builds inside the webview.
We are still working on the flow of Unity Integrations for Miniapp, We will be providing the Unity WebGL
Integration Kit soon
Prerequisites
- Node.js 18+ and a package manager (
pnpm,npm, oryarn) - A Telegram bot with Web Apps enabled (bot token, hosting URL configured)
- x402 provider account & API keys (Gx402 middleware will call/create/verify payments)
- Unity (2021+) for Unity WebGL exports (packaged into your web app that Telegram will load)
- Basic knowledge of wallet signing (on-chain EVM/Solana flows) or familiarity with Telegram Bot Payments if you intend to accept fiat invoices.
High-Level Flow (Telegram Mini-App + Gx402)
-
Launch & Auth (Telegram WebApp Init)
Usewindow.TelegramWebAppand theinitDatapayload for session/user context. -
Connect Wallet / Session
If you are using an on-chain wallet or in-app wallet connectors (Web3), initialize it.
If using Telegram Bot Payments for fiat, proceed with invoice flow. -
Create Payment Requirements (Gx402)
Frontend calls your backend (/api/createPayment) which uses Gx402’screatePaymentRequirements().
If no validX-402-Paymentheader, backend returns a 402 challenge. -
Sign & Send (On-chain) or Pay (Invoice)
- On-chain: Build/Sign transaction (e.g., Solana/EVM) in Unity/web client → receive
txSignature. - Invoice (fiat): Use Telegram Bot Payments API to create an invoice and let user pay.
- On-chain: Build/Sign transaction (e.g., Solana/EVM) in Unity/web client → receive
-
Verify & Unlock (Gx402)
Client sendsX-402-Payment: <txSignature_or_invoiceProof>in header to your verification endpoint.
Backend verifies transaction or invoice, then responds with200 OKand unlocks the asset/resource.
