Integrating Telegram Mini-Apps: Decentralized Wallet Binding, BOC Payload Signing & Replay Protection
Telegram Mini-Apps (TMAs) have established themselves as the premier frontend environment for Web3 consumer applications, enabling hundreds of millions of users to interact with decentralized finance, gaming, and social protocols without leaving their messaging client. However, bridging sandboxed web views with external non-custodial crypto wallets requires a trustless, cryptographically hardened communication channel. TonConnect 2.0 satisfies this requirement by providing an end-to-end encrypted session standard operating over Curve25519 ECDH key exchanges and AES-CBC symmetric ciphers. DApps authenticate via strict cryptographic manifests, negotiate bridge sessions over HTTP Server-Sent Events (SSE), and dispatch serialized Bag of Cells (BOC) transaction requests with microsecond precision. This technical guide examines TonConnect 2.0 session handshakes, manifest verification standards, BOC payload signing, and anti-replay protection.
Manifest Verification
Wallets validate domain origin via an immutable tonconnect-manifest.json hosted on the DApp's root domain, defeating phishing spoofing.
Curve25519 E2EE Bridge
All communication between the Mini-App and the wallet daemon is encrypted with shared secrets derived via ephemeral elliptic-curve Diffie-Hellman.
Replay Protection Nonce
Transaction payloads incorporate monotonic sequence numbers (subwallet_id / seqno) and valid-until expiration epochs.
Zero Key Exposure
Private seed phrases never enter WebApp memory; signing executes exclusively inside the secure enclave of the external wallet app.
1. Implementation Workflow: Integrating TonConnect 2.0 into Telegram Mini-Apps
Deploy the Cryptographic Manifest Specification
Create and host tonconnect-manifest.json at the root of your HTTPS domain. Specify your application name, icon URL, and legal privacy URLs. Non-custodial wallets fetch and verify this file prior to showing the authentication approval modal.
Initialize TonConnect UI Client SDK
Import @tonconnect/ui into your React or TypeScript frontend. Initialize the TonConnectUI instance passing your verified manifest URL. The SDK handles bridge polling, deep linking, and wallet selection modals automatically.
Assemble and Serialize the BOC Payload
When initiating smart contract interactions, construct the transaction message cell with opcodes, target addresses, and forward amounts. Serialize the structure into a base64-encoded Bag of Cells (BOC) and dispatch via tonConnectUI.sendTransaction().
Verify On-Chain Transaction Hash
The wallet signs the BOC and returns a signed BOC string containing the external message. Query a TON API indexer (e.g. TonCenter or TonAPI) using the message hash to confirm blockchain finality before fulfilling DApp digital goods.
2. Interactive Simulator: TonConnect 2.0 Handshake & BOC Signing Engine
"validUntil": 1789064120,
"messages": [{ "address": "EQB_k9...942", "amount": "5000000000", "payload": "te6cckEBAQEAKgAAU... [BOC Base64]" }]
}
3. Technical Comparison: TonConnect 2.0 vs. WalletConnect v2 vs. Injected Providers
4. Architectural Overview: E2EE Handshake & Payload Dispatch