Account Structure
Each account consists of two main components: a fixed 64-byte metadata header that defines the account’s properties and permissions, followed by variable-length data that can be up to 16MB in size. The metadata contains essential information like ownership, balance, and behavioral flags, while the data section stores arbitrary information that programs can read and modify.Account Metadata
Every account contains a 64-byte metadata header that defines its properties and state:Account format version. Currently supports version 1 (
TN_ACCOUNT_VERSION_V1 = 0x01).Bitfield controlling account behavior and permissions.
Size of the account’s data in bytes. Maximum value is 16MB (
TN_ACCOUNT_DATA_SZ_MAX = 16,777,216).Account sequence number that is incremented each time the account is modified during transaction execution. The sequence is updated at the end of the transaction for accounts that were modified.
32-byte public key of the program that owns this account. Only the owner program can modify account data.
Account balance in the network’s native token. Used for transaction fees and transfers.
Transaction nonce for replay protection. Must match the transaction nonce exactly for fee payer accounts. See Transaction Execution for more details.
Account Data
Following the 64-byte metadata header, accounts can store up to 16MB of arbitrary data that programs can read and modify through direct memory access in the VM.For detailed information about how programs access account data in memory, see the VM Memory Layout documentation.
Ownership Model
Program Ownership
Every account is owned by exactly one program, identified by theowner field
in the account metadata. Ownership is permanent and cannot be transferred.
Only the owner program can:
- Modify account data during transaction execution
- Change account metadata (except balance and nonce)
- Delete the account by setting the
TN_ACCOUNT_FLAG_DELETEDflag
Externally Owned Accounts
Externally owned accounts (EOAs), also known as user accounts, are owned by the externally owned account program, which is located at the address0 (all zeros). They can be accessed by using the private key
corresponding to their address. EOAs are created using tsys_account_create_eoa()
with signature verification to prove ownership of the private key.
Account Types
Thru supports two fundamental account types that determine their lifecycle and storage characteristics:- Permanent Accounts
- Ephemeral Accounts
Purpose: Long-lived accounts that persist in the network state indefinitely.Characteristics:
- Default account type (no special flags required)
- Require state proofs for creation to prevent conflicts
- Persist in state trees even when deleted
- Can be compressed to optimize storage
- Support all account flags and operations
- Created with
tsys_account_create()using state proofs - When deleted, account is completely removed but can be recreated without another state proof for a time before compression
- Newly created accounts that have never existed before can be deleted like ephemeral accounts
- User wallets and token accounts
- Program accounts containing executable code
- Application data and state storage
- System contracts and infrastructure
Account Purposes
While there are only two fundamental types, accounts serve various purposes based on their flags and ownership:User Accounts (EOAs)
User Accounts (EOAs)
Purpose: Store user funds and serve as transaction fee payers.Also known as: Externally Owned Accounts (EOAs)Characteristics:
- Owned by the externally owned account program at address
0(all zeros) - Created with
tsys_account_create_eoa()using signature verification - Controlled by the holder of the private key corresponding to the account’s public key address
- Typically have no custom data (data_sz = 0)
- Used for balance transfers and fee payments
Program Accounts
Program Accounts
Purpose: Store executable bytecode for smart contracts.
- Marked with
TN_ACCOUNT_FLAG_PROGRAM - Contain compiled program code in account data
- Immutable once deployed and verified
Data Accounts
Data Accounts
Purpose: Store arbitrary application state and user data.
- Owned by specific programs that can modify them
- Most flexible storage option up to 16MB
- Used for application state, user profiles, game data
System Accounts
System Accounts
Purpose: Core network infrastructure and privileged operations.
- Marked with
TN_ACCOUNT_FLAG_PRIVILEGED - Special permissions for network-level operations
- Protected from normal program access
Account Limitations
Size Constraints
Each account can store at most 16,777,216 bytes of data (
TN_ACCOUNT_DATA_SZ_MAX).Access Permissions
Read Access
Read Access
Any program can read account metadata and data from accounts included in the transaction.
Write Access
Write Access
Only the owner program can modify account data. System operations can modify balance and nonce fields.
Creation Rights
Creation Rights
New accounts can only be created by their designated owner program during transaction execution.
Account Lifecycle
Creation
Programs create accounts using the system call interface:1
Create Account
Use
tsys_account_create() or tsys_account_create_ephemeral() to create a new account:For detailed syscall documentation, see the System Calls reference.
The account is immediately available for use within the same transaction.
2
Set Initial Size
If the account needs data storage, resize it using
tsys_account_resize():See
tsys_account_resize() for complete parameter details.Active State
Active accounts exist in the current state and can be:- Read by any program in transactions that include them
- Modified by their owner program through direct memory access
- Transferred funds using
tsys_account_transfer() - Resized using
tsys_account_resize() - Used as data storage for applications
An account is considered active if it’s not compressed and not both ephemeral and deleted.
Compression
Programs can compress accounts to optimize state storage using the compression syscalls:See
tsys_account_compress() and tsys_account_decompress() for detailed usage.- Calling
tsys_account_compress()on an ephemeral account immediately deletes it instead of compressing - Relaxed permissions: Any program can compress (delete) an ephemeral account if it’s writable in the transaction
- No ownership check: Unlike
tsys_account_delete(), compression doesn’t require the current program to own the account - No state proof required since the account is simply removed
Deletion
1
Delete Account
Programs delete accounts using the deletion syscall:This sets the
TN_ACCOUNT_FLAG_DELETED flag, making the account data inaccessible.See
tsys_account_delete() for complete documentation.2
Ephemeral Cleanup
Accounts marked both
TN_ACCOUNT_FLAG_EPHEMERAL and TN_ACCOUNT_FLAG_DELETED can be garbage collected by the runtime.3
Permanent Deletion
Non-ephemeral deleted accounts are marked with the
TN_ACCOUNT_FLAG_DELETED flag as a tombstone in the state tree.Account Operations
Balance Transfers
Programs can transfer funds between accounts using the transfer syscall:See
tsys_account_transfer() for usage details and requirements.Flag Management
Programs can modify account flags using the set flags syscall:See
tsys_account_set_flags() for available flags and restrictions.Making Accounts Writable
Before modifying account data, programs must mark accounts as writable:See
tsys_set_account_writable() for detailed requirements.