7Block Labs
Blockchain Development

ByAUJay

TON Development Services: Smart Contracts, Bots, and Mini Apps on TON

Short summary: TON is now a practical path to deploy consumer-scale Web3 in Telegram: audited smart‑contract languages (Tolk/Tact), native payments (Stars, USDT), full‑screen Mini Apps, and 50/50 ad‑revenue payouts in Toncoin. This post distills what decision‑makers need to build secure, monetizable apps on TON in 2025 with concrete patterns, code, and architecture guidance. (blog.ton.org)


Why build on TON now (2025)

  • Telegram turned on creator monetization with a 50/50 ad revenue split, paying exclusively in Toncoin over TON—unlocking an instant business model for channels and apps. (theblock.co)
  • Mini Apps have matured: full‑screen, homescreen shortcuts, secure/local storage, and subscription tiers via Stars. (core.telegram.org)
  • For digital goods, Telegram Stars are the mandated in‑app currency; developers can convert Stars to Toncoin (or discounted ads), solving iOS/Play billing constraints while remaining crypto‑compatible. (core.telegram.org)
  • Stablecoin rails: USDT is live on TON (supported by major exchanges and wallets), enabling consumer‑grade payments and settlements. (cointelegraph.com)
  • Scale is real: audited stress tests hit 104,715 TPS, and TON’s dynamic sharding (“infinite sharding”) keeps throughput elastic. (blog.ton.org)

What this means: you can ship monetizable, low‑fee, Web2‑grade experiences to a billion‑user social graph—without teaching users new UX.


What we build at 7Block Labs on TON

  • Product strategy for Telegram-native experiences (growth loops, Stars monetization, TON on‑chain components).
  • Smart contracts in Tolk/Tact: tokens (Jettons, NFTs 2.0), payments, escrows, sales, auctions, loyalty, data registries.
  • Telegram Bots that operate as acquisition and orchestration layers (deep links, inline flows, Star subscriptions, PSP for physical goods).
  • Full Telegram Mini Apps with TonConnect wallet flows, USDT checkout, and observability.
  • Infrastructure: indexers, webhooks, and nodes; CI for contracts; security reviews; gas/cost optimization; telemetry.

Smart contracts on TON: languages, fees, and patterns

Languages you’ll use in 2025

  • Tolk (recommended): modern, statically‑typed, compiles to TVM with lower gas; now the primary language for TON smart contracts. (docs.ton.org)
  • Tact: TypeScript‑like, excellent ergonomics; compiler underwent Trail of Bits assessment; widely adopted and still supported. (docs.ton.org)
  • FunC: legacy but battle‑tested; still useful for reading older references and standards.

Quickstart developer workflow:

  • Initialize with Blueprint and choose a Tolk/Tact template:
    npm create ton@latest
    npx blueprint create <CONTRACT> --type tolk-counter
    (docs.ton.org)

Costs and fees, precisely

TON fee math splits into storage, compute (gas), and forwarding fees. Gas price is set by network config; as of current docs, basechain gas price examples show per‑gas costing via config params 20/21, with helper functions to derive nanotons; do not hardcode absolute TON amounts—derive from config and measure. (docs.ton.org)

Best practices:

  • Keep a positive reserve; measure your contract’s max cell/bit footprint to bound storage; never hardcode fee amounts. (docs.ton.org)
  • Prefer bounceable internal messages; always handle bounced messages and never execute the embedded query on bounce. (docs.ton.org)
  • Use user‑friendly addresses correctly: bounceable vs non‑bounceable flags, testnet marker, and checksum rules. (docs.ton.org)

Asynchronous model and idempotency

TON is message‑driven and sharded; treat every handler as at‑least‑once. Patterns that work:

  • Include query_id and replay windows in messages; ignore duplicates.
  • Separate read models off‑chain (TonAPI/Toncenter) and write with on‑chain contracts. Direct cross‑contract “reads” aren’t like EVM; design for messages. (tondev.org)
  • Simulate complex race scenarios (e.g., concurrent bounces) in sandbox; emerging research tooling focuses on temporal bugs in TON’s async model. (arxiv.org)

Example Tolk contract snippet (safe counter with bounce handling)

// contracts/counter.tolk
struct Storage { counter: int64, lastQuery: int64 }

fun Storage.load() { return Storage.fromCell(contract.getData()); }
fun Storage.save(self) { contract.setData(self.toCell()); }

type Op = Inc | Reset
struct Inc { query_id: int64, by: int32 }
struct Reset { query_id: int64 }

receive in_msg {
  // Reserve original balance + any due storage; fail-safe against depletion.
  contract.reserveWithStorage(); // helper in stdlib

  if (in_msg.isBounced()) {
    // Never execute original payload on bounce
    return ();
  }

  // Decode operation lazily to save gas
  let op = lazy Op.fromSlice(in_msg.body);

  var s = lazy Storage.load();
  let now = now();

  match (op) {
    Inc => {
      if (op.query_id <= s.lastQuery) return (); // idempotent
      s.counter += op.by;
      s.lastQuery = op.query_id;
    }
    Reset => {
      if (op.query_id <= s.lastQuery) return ();
      s.counter = 0;
      s.lastQuery = op.query_id;
    }
  }

  s.save();
}

Notes:

  • reserveWithStorage()
    illustrates the “cover storage on demand” strategy described in the fee docs. (docs.ton.org)

Standards you’ll rely on

  • Jettons (fungible tokens) and NFTs with TEP‑62/64/66; NFT 2.0 adds enforceable royalty signaling across the ecosystem. Reference implementations exist and are production‑ready. (docs.ton.org)
  • TON DNS/TON Sites/TON Proxy let you bind .ton domains to contracts and serve decentralized sites—useful for on‑chain identity and app endpoints. (docs.ton.org)
  • TON Payments (payment channels) enables instant micropayments for metered services. (docs.ton.org)
  • TON Storage provides decentralized “bags of files” for assets and app data; works with DNS and Payments. (docs.ton.org)

Bots: acquisition, monetization, and orchestration

Telegram bots are the front door to your TON app. In 2024–2025, three monetization rails matter:

  1. Stars for digital goods (in‑app compliant)
  • For subscriptions and digital items, use “XTR” (Stars). Create recurring invoices; users pay inside Telegram; you can convert Stars to Toncoin or ad credit with ~30% ad discount. Implement /paysupport and refunds per policy. (core.telegram.org)
  1. PSPs for physical goods
  • For tangible goods/services, use the Bot Payments API with providers like Stripe (Apple Pay/Google Pay supported). Follow Stripe’s restricted business lists and provider checklists. (core.telegram.org)
  1. Ad revenue share in Toncoin
  • If you operate channels, Telegram shares 50% of ad revenue, settled on TON. Build bots that convert viewers into Mini App users and funnel Stars and ads into a single P&L. (theblock.co)
  • Use startapp and startattach to pass parameters into Mini Apps; keep within allowed charset and length. (docs.telegram-mini-apps.com)
  • Direct Mini App links:
    t.me/<bot>/<short_name>?startapp=...&mode=fullscreen|compact
    . (core.telegram.org)
  • Programmatic open (clients):
    messages.requestAppWebView
    with flags for fullscreen/compact and write permission. (core.telegram.org)

Security: validate initData correctly

  • On your server, verify Telegram WebApp initData with HMAC‑SHA256 using your bot token; for third‑party sharing, verify the new Ed25519 signature with Telegram’s public key. Reject stale
    auth_date
    . (core.telegram.org)

Example (Node, minimal idea):

import { verifyTelegramInitData } from 'tg-user-validation'; // community lib
const ok = verifyTelegramInitData(initData, process.env.BOT_TOKEN, { maxAgeSeconds: 300 });
if (!ok) throw new Error('Invalid initData');

(libraries.io)

Stars subscription example (Node + Telegraf)

import { Telegraf } from 'telegraf';
const bot = new Telegraf(process.env.BOT_TOKEN!);

bot.command('subscribe', async (ctx) => {
  const link = await ctx.telegram.createInvoiceLink({
    title: 'Pro Plan',
    description: 'Monthly access to premium features',
    payload: `sub:${ctx.from?.id}:${Date.now()}`,
    currency: 'XTR', // Telegram Stars
    prices: [{ label: 'Monthly', amount: 499 /* 4.99 USD in Stars */ }],
    subscription_period: 30 * 24 * 60 * 60, // recurring monthly
  });
  return ctx.reply(`Subscribe: ${link}`);
});

bot.launch();
  • The
    currency: 'XTR'
    triggers the Stars payment rail and recurring billing. (core.telegram.org)

Mini Apps: full‑fidelity apps inside Telegram

What changed recently:

  • Full‑screen mode, homescreen shortcuts, DeviceStorage/SecureStorage for persistence, and richer APIs shipped across Bot API 8.0–9.1. (core.telegram.org)

Core stack for production:

  • React/Vue Mini App + TonConnect UI for wallet connection
  • USDT/Toncoin settlement via TonConnect or deep links
  • Webhooks/indexer to update state and receipts

Wallet connection in Mini App (React)

import { TonConnectUIProvider, TonConnectButton, useTonConnectUI } from '@tonconnect/ui-react';

export default function App() {
  return (
    <TonConnectUIProvider manifestUrl="https://your.app/tonconnect-manifest.json">
      <TonConnectButton />
      <Checkout />
    </TonConnectUIProvider>
  );
}

function Checkout() {
  const [tonConnectUI] = useTonConnectUI();
  const pay = async () => {
    await tonConnectUI.sendTransaction({
      validUntil: Math.floor(Date.now()/1000) + 300,
      messages: [{ address: 'EQC...', amount: '50000000', text: 'Order #123' }]
    });
  };
  return <button onClick={pay}>Pay 0.05 TON</button>;
}
  • Host a compliant
    tonconnect-manifest.json
    ; avoid CORS/proxies and ensure direct GET access. (ton-connect.github.io)

If you don’t need signature tracking, deep links are the simplest:

ton://transfer/<ADDRESS>?jetton=<USDT_MASTER>&amount=5000000&text=order-123
  • Note: USDT amount is in micro‑USDT (6 decimals), not nanoTON. (docs.ton.org)

When to use what

  • TonConnect: you need “who paid,” signature tracking, multiple messages, or programmatic retries.
  • ton:// deep links: fast UX, QR‑friendly, no wallet connection state.

Architecture blueprint (battle‑tested)

  • Frontend: Telegram Mini App (React/Vue). Persist SKU/cart in
    DeviceStorage
    and secure tokens in
    SecureStorage
    . (core.telegram.org)
  • Identity: Telegram initData + your server session (after validation).
  • Payments:
    • Digital goods: Stars (with optional withdraw to TON via Fragment). (theblock.co)
    • Physical goods: Bot Payments API + Stripe/PSP (Apple Pay/Google Pay). (core.telegram.org)
    • Crypto rails: TonConnect, USDT/TON.
  • Smart contracts:
    • Tolk/Tact modules for escrow, loyalty Jetton, or NFT 2.0 inventory.
    • Strict message schemas with query_ids; bounced handling.
  • Indexing & reads:
    • TonAPI (REST/webhooks) or Toncenter JSON‑RPC; use webhooks for confirmations and balance events. (docs.tonapi.io)
  • Observability:
    • Alert on non‑zero exit codes, bounce spikes, storage_due growth.
  • Growth:
    • startapp
      deep links in channels; Main Mini App configuration via @BotFather; align store metadata for Mini App Store featuring. (core.telegram.org)

Security and compliance checklist

  • Smart contracts:
    • Unit tests in Blueprint; fuzz message order; measure worst‑case storage; avoid unbounded maps. (docs.ton.org)
    • Static/dynamic analysis; consider emerging simulators for async races. (arxiv.org)
  • Mini App/Server:
    • Validate initData (HMAC) and, when sharing with partners, require Ed25519 signature verification using Telegram’s published key. Enforce
      auth_date
      TTL. (core.telegram.org)
  • Payments policy:
    • Digital goods must use Stars inside Telegram. Implement
      /paysupport
      and refund flows. (core.telegram.org)
    • Physical goods via PSP must follow provider risk/restrictions (e.g., Stripe RB/Prohibited list). (stripe.com)

Running your own infra (when you need it)

  • Indexer/API: TonAPI (SaaS) with REST, webhooks, and SDKs; or run open TON HTTP API (toncenter) with modest compute. (docs.tonapi.io)
  • Liteservers/Nodes: For archival nodes, plan serious hardware: recent guidance notes ~16 CPU cores, 128 GB RAM, and 16–20 TB SSD. (archival-dump.ton.org)

Practical examples we deliver

  1. Channel-commerce with Stars + USDT
  • Discovery via channel posts →
    startapp
    deep link → Telegram Mini App product UI.
  • Digital items sold via Stars subscriptions; premium add‑ons via one‑time Stars invoices.
  • Settlement treasury converts Stars → Toncoin; on‑chain payouts for partners. (theblock.co)
  1. Loyalty Jetton with off‑chain state
  • Jetton mint/burn on Tolk; balances read via TonAPI; earn via bot quests.
  • NFT 2.0 for tiers with automatic royalty rules for secondary items. (docs.ton.org)
  1. USDT checkout for physical goods
  • Bots send invoices through PSP (Stripe) for shipping info, taxes; post‑purchase, a Mini App lets users tip in Stars or TON. (core.telegram.org)

Performance and scale notes for leadership

  • TON’s architecture: dynamic sharding across workchains/shardchains, with an “accountchain” concept that composes into shard blocks—this is why throughput scales with load. (docs.ton.org)
  • Verified speed: 104,715 TPS on 256 validators, audited by CertiK; elastic sharding split to 512 shards during test. (blog.ton.org)
  • Payment UX: USDT live on TON reduces pricing volatility and accounting overhead; supported by major exchanges and Wallet in Telegram. (cointelegraph.com)

Emerging best practices (2025)

  • Prefer Tolk for new builds; expect 30–50% lower gas vs legacy code, with friendlier tooling and IDE LSP. (docs.ton.org)
  • Use TonConnect inside Mini Apps for identifiable payers; reserve ton:// links for quick “guest checkout” or QR flows. (ton-connect.github.io)
  • For high‑volume flows, offload reads to TonAPI webhooks and treat the blockchain as your write‑ahead log; never block user UX on cross‑contract reads. (docs.tonapi.io)
  • For address UX, default to bounceable for contracts, non‑bounceable when funding new (uninitialized) accounts. Wallets already toggle bounce based on initialization. (docs.ton.org)
  • Add
    exp
    (expiry) to deep links to mitigate late replays of signed payloads. (beta-docs.ton.org)

How we engage (7Block Labs)

  • 2–3 week Discovery: monetization model (Stars vs TON/USDT), user flows, and contract map.
  • 6–10 week MVP: Mini App + Bot + on‑chain module; staged to channel pilots.
  • Scale: payments/risk review, incident‑ready telemetry, A/B growth loops with deep links and Main Mini App setup.

If you want a Toncoin‑settled business inside Telegram—ads, Stars, and stablecoin rails together—TON is finally production‑grade. Let’s scope your pilot.

Sources: TON Docs/Blog, Telegram Bot API, and reputable industry coverage linked inline. (docs.ton.org)

Like what you're reading? Let's build together.

Get a free 30‑minute consultation with our engineering team.

Related Posts

7BlockLabs

Full-stack blockchain product studio: DeFi, dApps, audits, integrations.

7Block Labs is a trading name of JAYANTH TECHNOLOGIES LIMITED.

Registered in England and Wales (Company No. 16589283).

Registered Office address: Office 13536, 182-184 High Street North, East Ham, London, E6 2JA.

© 2025 7BlockLabs. All rights reserved.