Exploring TON Blockchain Data Analysis with Dune: A Quickstart Guide

Exploring TON Blockchain Data Analysis with Dune: A Quickstart Guide

The views expressed in this article are those of the author and do not necessarily represent the opinions or endorsements of TON. This content is for informational purposes only and should not be considered financial or investment advice.


With TON now powering Telegram’s mini app ecosystem, the Web3 space is reaching over 950 million users, bringing crypto to the masses like never before. As this growth continues to surge, understanding on-chain activity becomes increasingly important. So, how do we track and analyze what’s happening on the TON blockchain?


The answer lies in data. As TON’s ecosystem expands, the ability to analyze on-chain data is key to understanding user behavior, adoption trends, and DeFi activity. This article will walk you through TON's architecture and show you how to leverage Dune’s blockchain data tools to analyze this fast-growing network.


TON Blockchain: Key Architectural Features

TON Blockchain is built on a unique asynchronous architecture where transactions are driven by messages. These are data packets exchanged between users, applications, and smart contracts. Every message carries specific instructions—such as updating storage or triggering further messages—and can be inbound (sent to a contract) or outbound (sent from a contract).


To ensure messages are processed in the correct order, TON uses Logical Time (LT) to sequence events. Unlike traditional blockchains, which process transactions sequentially, TON’s asynchronous nature allows actions—like a DEX swap—to generate multiple messages processed across various blocks. This sharded design enables TON to handle high volumes of transactions with scalability and efficiency.


However, TON’s architecture differs significantly from EVM-based chains, which can pose challenges for onboarding new developers. To address this, the TON Foundation has organized TON's blockchain data into a public data lake (see ton-etl for more details), making it easier for analysts to use familiar tools like SQL and Dune.


Getting Started with TON Data on Dune

Dune is a popular blockchain analytics platform that simplifies querying, visualizing, and interpreting on-chain data. It supports both EVM and non-EVM chains, including TON, enabling users to analyze public datasets, run SQL queries, and compile them into dashboards.


Steps to Get Started:


  • Sign up for a free account on Dune.


  • Once registered, click Create, then select New query from the dropdown menu.


Understanding TON Data on Dune

On Dune, all available data can be categorized into several types:


  • Raw Data: This includes low-level, foundational data about TON’s network activity.


  • Decoded Data: This data is presented in a more user-friendly format, with information like DEX trades, jetton events, and liquidity pool details.


  • Views and Materialized Views: Pre-compiled views to simplify complex queries.


  • Off-Chain Data Uploads: External data that can be uploaded and integrated into Dune’s platform.


Tables for Blockchain Activity

Key tables include:


  • ton.blocks – Details about each block in the blockchain.


  • ton.transactions – Information about all transactions on the network.


  • ton.messages – Data about messages sent or received, including the source, destination, and direction of the interaction.


These tables are fundamental for analyzing TON’s network activity, including account states, opcodes, and transaction flows.


How to Query TON Transactions

Let’s begin by writing a basic query . For example, we can calculate the average number of transactions per second over the past 30 days:


Query:


  • 1. SELECT


  • 2. COUNT(*) / (COUNT(DISTINCT date)) AS avg_transactions_per_second


  • 3. FROM ton.transactions


  • 4. WHERE block_date > CURRENT_DATE - INTERVAL '30 days'



You can also use the ton.blocks and ton.messages tables for similar analyses. Some transactions, such as system tick-tock transactions by the Elector Contract. may not generate any messages.

In TON, each transaction has one incoming message but may generate multiple outgoing messages. These messages are stored twice in the ton.messages table with a "direction" column indicating whether the message was sent (in) or received (out).


There are three types of messages:


  • External – The source is null, and only the "in" direction exists.


  • Internal – Both source and destination are non-null, with both "in" and "out" directions.


  • Logs – The destination is null, and only the "out" direction exists.


For more specific analysis, you can filter by direction. For example, to track smart contract execution, filter for direction = ‘in’ and destination = [contract address].


Optimizing Queries for Performance

TON generates vast amounts of data, so writing optimized queries is essential for efficiency. For example, using a query like SELECT COUNT(*) FROM ton.transactions could result in slow performance because it scans over 2 billion rows.


Tips for Faster Queries:


  • Only Select Necessary Columns: Avoid using SELECT *. Only choose the columns you need for analysis.


  • Filter by Block Date: Each raw TON table is partitioned by the block_date column. Filtering by date partitions can significantly speed up your queries.


Address Formats and Transaction Hashes

TON addresses can be represented in multiple formats, including raw bytes (starting with '0:'), user-friendly format (starting with 'EQ'), and bounceable user-friendly format (starting with 'UQ'). Dune tables use the raw address format by default.


You can use Dune’s built-in functions to convert between address formats:


  • ton_address_raw_to_user_friendly()


  • ton_address_user_friendly_to_raw()


If you encounter different formats for transaction hashes between platforms (for instance, between Tonviewer and Dune), you can use the following snippet to convert them:


  • Tonviewer: 692263ed0c02006a42c2570c1526dc0968e9ef36849086e7888599f5f7745f3b


  • Dune: aSJj7QwCAGpCwlcMFSbcCWjp7zaEkIbniIWZ9fd0Xzs=


Decoded Tables for Specific On-Chain Events

Certain on-chain activities, like transfers, mints, and burns of jettons, are already decoded and made available in user-friendly tables:


  • ton.jetton_events: For jetton transfers, mints, and burns.


  • ton.dex_trades: For trades on decentralized exchanges (DEXs) and launchpads.


  • ton.dex_pools: For liquidity pool snapshots and total value locked (TVL) data at each block.


These decoded tables simplify common analyses. For instance, to track the total transaction volume and number of active wallets using USDT on TON over the past 30 days, you can query the ton.jetton_events table.


Materialized Views for Simplified Data Access

Materialized views pre-compute and store the results of complex queries to improve performance. Examples include:


  • Jetton Metadata Latest Values: To track updates to jetton metadata (like decimals and symbols).


  • DEX Pools Latest Values: To track the most recent values of liquidity pools without recalculating them on every query.


Bonus: Labels and Application Activity

TON Foundation labels addresses belonging to popular DeFi, GameFi, and other applications. These labels are available in Dune’s dune.ton_foundation.dataset_labels table, which you can use to filter and analyze specific app activities on the network.


Next Steps: Deep Dive into TON Data

Ready to explore further? For more resources, materialized views, and pre-built dashboards, check out the following:


  • TON Quick Start Guide


  • Popular Dashboards on Dune



  • TON Data Hub Community


The TON Data Hub is a collaborative space where developers, analysts, and contributors can share insights, collaborate on projects, and stay updated on the latest trends in TON’s blockchain data.

By diving into these tools, you can gain valuable insights into TON's growth, user behavior, and DeFi activity, helping you understand the future of this rapidly expanding ecosystem.


Join the TON Data Hub Community

Stay updated with the latest news, integrations, and data insights from the TON ecosystem. Participate in hackathons, contests, and contribute to paid dashboard requests—join. "Join the community today!

Disclaimer: The content on this website is for informational purposes only and does not constitute financial or investment advice. We do not endorse any project or product. Readers should conduct their own research and assume full responsibility for their decisions. We are not liable for any loss or damage arising from reliance on the information provided. Crypto investments carry risks.