Web3 DApp Integration: TON Connect, Wallet Signing & Smart Contract Calls
Step 098: Web3 DApp Integration: TON Connect, Wallet Signing & Smart Contract Calls
The true convergence of Telegram's 950-million-user reach and decentralized finance lives inside The Open Network (TON). Through TON Connect 2.0, Telegram Mini Apps (TMA) bridge seamlessly into non-custodial Web3 wallets (Tonkeeper, Telegram Wallet @wallet, MyTonWallet) without exposing private seed phrases or forcing users out of the chat client. In Telegram 198, we dissect the end-to-end Web3 DApp stack: implementing the cryptographic ton_proof authentication handshake to eliminate server replay attacks, constructing binary Bag of Cells (BOC) payloads for Jetton transfers (USDT, NOT, DOGS), and executing on-chain smart contract transactions with real-time explorer trace verification.
1. Architectural Foundation: The TON Connect 2.0 Universal Bridge
TON Connect 2.0 establishes a secure, bi-directional communication channel between a web-based DApp and a non-custodial crypto wallet. When running inside a Telegram Mini App on mobile, connection requests dispatch native deep links (tc://...); in desktop browsers, communication relays over an encrypted HTTP Server-Sent Events (SSE) bridge server using ephemeral Curve25519 keypairs:
TonConnect UI SDK
React/Vite integration with @tonconnect/ui-react. Renders native connect modal, displays wallet address, and auto-restores active sessions on reload.
SSE Cryptographic Bridge
DApp and Wallet negotiate shared secrets via Curve25519 ECDH. Messages relay across bridge endpoints with zero plaintext visibility to bridge operators.
Zero-Trust Signing
Your DApp never sees private keys. The wallet prompts the user with the exact recipient, Jetton amount, and network gas fee before cryptographic authorization.
2. The ton_proof Handshake: Cryptographic On-Chain Authentication
Never authenticate users by trusting their wallet address sent in a client request. Malicious users can send any address. Instead, enforce ton_proof:
3. Bag of Cells (BOC) Construction & Smart Contract Calls
Everything in TON data structures is serialized as a Bag of Cells (BOC). When initiating token transfers or interacting with custom Tact / FunC smart contracts (such as Jetton transfers conforming to TEP-74), you build binary cell trees:
4. Interactive Lab: TON Connect 2.0 DApp & Wallet Signing Simulator
Experience the entire Web3 DApp flow inside Telegram. Select your preferred wallet, perform the ton_proof cryptographic handshake, compile a serialized Jetton BOC payload, and broadcast to the blockchain:
5. Master Architectural Blueprint & Web3 Stack
Inspect the complete Web3 DApp blueprint showing TON Connect 2.0 layers, the 4-step cryptographic ton_proof handshake sequence, and TEP-74 Jetton BOC serialization:
6. Web3 Production FAQs & Security Directives
Q1: Why is ton_proof mandatory if the client already provides the wallet address?
Any client can forge an HTTP request claiming to own a whale wallet address (e.g. holding 100,000 TON). ton_proof proves possession of the private key by signing a dynamic backend-generated nonce over your domain with an Ed25519 cryptographic signature.
Q2: What is the difference between raw TON transfer and a Jetton transfer?
A simple TON transfer sends native coin directly to the recipient's address. A Jetton transfer (such as USDT or NOT) requires sending an internal smart contract message to the sender's Jetton Wallet contract with opcode 0x0f8a7ea5, which burns/updates balance and dispatches an internal notification to the recipient.
Q3: How do I verify on-chain that a transaction actually completed successfully?
When sendTransaction returns the signed BOC, extract the transaction hash or poll TON Center API v2 (or TON Access) for incoming transactions on your receiving address with matching forward_payload memo string.
Q4: Where must the tonconnect-manifest.json file be hosted?
It must be served over HTTPS on a publicly accessible domain with valid CORS headers (Access-Control-Allow-Origin: *). It contains your DApp name, high-res icon URL, and terms of service link shown inside wallet authorization sheets.
Q5: Why do Jetton transactions attach 0.05 TON if paying in USDT?
Smart contracts on TON require execution gas and storage rent. The attached 0.05 TON pays validator computational fees. Any unused gas is automatically refunded back to the sender's address via the response_destination parameter.
Advancing to Step 099: Developer Roadmap: AI Agents, LangChain & Autonomous Ecosystem
You are standing at the threshold of the 100-step summit! In Step 099, we unite modern Large Language Models with the Telegram platform: architecting autonomous AI Agents with LangChain, function calling tools, vector search RAG memory, and multi-agent supervisory networks.