Transaction
In the TON blockchain, any change to an account's state is recorded via a transaction. Unlike messages, transactions do not move, send, or receive anything. These terms are often confused, but it's important to understand that a transaction is simply a record of all changes that occurred to a specific account.
In this section, you’ll explore how a transaction is structured—how it progresses through each phase, how to retrieve transaction data using APIs, and how to determine whether an on‑chain event is successful.
Transaction structure
TL-B
Before diving into how transactions work in TON, we first need to understand their structure using TL-B(Type Language – Binary). It's worth noting that there are several types of transactions in TON; however, for this guide, we will focus solely on ordinary transaction. These are the transactions relevant for payment processing and the development of most applications built on TON.
trans_ord$0000 credit_first:Bool
storage_ph:(Maybe TrStoragePhase)
credit_ph:(Maybe TrCreditPhase)
compute_ph:TrComputePhase action:(Maybe ^TrActionPhase)
aborted:Bool bounce:(Maybe TrBouncePhase)
destroyed:Bool
= TransactionDescr;
According to the TL-B schema, a transaction consists of the following fields:
Field | Type | Description |
---|---|---|
credit_first | Bool | Indicates whether the credit phase should be executed first. This depends on whether the bounce flag is set. This will be explained in more detail in a later section. |
storage_ph | Maybe TrStoragePhase | The storage phase, responsible for handling fees related to the account's persistent storage. |
credit_ph | Maybe TrCreditPhase | The credit phase, responsible for processing the transfer of value delivered with the incoming message, if it's an internal message (types #1 or #2). |
compute_ph | TrComputePhase | The compute phase, responsible for executing the smart contract code stored in the account's code cell. |
action | Maybe ^TrActionPhase | The action phase, responsible for handling any actions generated during the compute phase. |
aborted | Bool | Indicates whether the transaction was aborted during one of the phases. If true , the transaction was not executed, and changes from the compute_ph and action phases were not applied. |
bounce | Maybe TrBouncePhase | TrBouncePhase The bounce phase, responsible for handling errors that occurred during the compute_ph or action phases. |
destroyed | Bool | Indicates whether the account was destroyed during the execution of the transaction. |
Other types of transactions—such as trans_storage, trans_tick_tock, trans_split_prepare, and others—are used for internal events that are invisible to end users. These include shard splitting and merging, tick-tock transactions, etc.
Since they are not relevant to DApp development, we will not cover them in this tutorial.
Credit phase
This phase is relatively small and straightforward. If you look at the blockchain source code, you’ll see that the main logic of this phase is to credit the contract’s balance with the remaining value from the incoming message.
credit_phase->credit = msg_balance_remaining;
if (!msg_balance_remaining.is_valid()) {
LOG(ERROR) << "cannot compute the amount to be credited in the credit phase of transaction";
return false;
}
// NB: msg_balance_remaining may be deducted from balance later during bounce phase
balance += msg_balance_remaining;
if (!balance.is_valid()) {
LOG(ERROR) << "cannot credit currency collection to account";
return false;
}
The credit phase is serialized in TL-B as follows:
tr_phase_credit$_ due_fees_collected:(Maybe Grams)
credit:CurrencyCollection = TrCreditPhase;