Skip to main content

Midnight's hybrid architecture

Midnight combines approaches to create a hybrid architecture that doesn't force you to choose between models but integrates both to maximize benefits.

The combination

Midnight is a data-protecting blockchain that made a deliberate architectural choice: instead of forcing developers into one paradigm, it provides both UTXO and account-based capabilities. This isn't just about having options—it's about using the right tool for the right job.

At its foundation, Midnight operates on a UTXO model. This choice enables the natural parallelism and privacy features we explored in the previous lesson. NIGHT tokens, Midnight's native utility token, exist as UTXOs on the ledger. But here's where Midnight innovates beyond other UTXO chains: NIGHT tokens serve a special purpose. They generate DUST, a renewable resource that powers all transactions on the network. This NIGHT-generates-DUST mechanism is fundamental to Midnight's economic model and ensures predictable transaction costs.

On top of this UTXO foundation, Midnight introduces a smart contract layer that can operate using account-based patterns. When you deploy a Compact smart contract (Midnight's smart contract language), it can maintain complex state just like contracts on Ethereum. This means developers can write intuitive smart contracts with familiar patterns while the underlying platform still benefits from UTXO advantages.

Understanding Midnight's token ecosystem

Before we dive deeper into token types in future chapters, let's establish a clear framework for understanding how value moves through Midnight's ecosystem. The key insight is understanding the distinction between tokens (which represent value) and resources (which enable network operations).

The NIGHT token and DUST resource

NIGHT is Midnight's native utility token that exists as UTXOs on the ledger. Think of NIGHT as a renewable energy source—like solar panels that generate electricity. Just as solar panels produce energy when exposed to sunlight, NIGHT tokens continuously generate DUST when designated to a DUST address.

DUST is not a token—it's a shielded network resource used exclusively to pay for transaction fees. The amount of DUST you can store is proportional to your NIGHT balance, and DUST decays when disconnected from its generating NIGHT tokens. This unique mechanism provides operational predictability: as long as you hold NIGHT, you can execute transactions without worrying about volatile gas prices.

Token categories

Beyond the NIGHT/DUST dynamic, Midnight supports two fundamental categories of tokens:

  • Ledger Tokens live directly on Midnight's blockchain, managed by the core protocol itself. These tokens exist as UTXOs and benefit from the highest level of security and efficiency. They can be either shielded (private) or unshielded (transparent), giving users control over their privacy preferences. Because they're handled by Midnight's optimized UTXO engine, they process with maximum efficiency and don't require trusting any smart contract code.

  • Contract Tokens are created and managed by Compact smart contracts. These tokens use account-based patterns within the contracts, maintaining balances and state similar to ERC-20 tokens on Ethereum. With contract tokens, you can program custom logic, implement complex distribution mechanisms, or create tokens that interact with other contracts. These also support both shielded and unshielded variants, though the implementation differs from ledger tokens.

Token types

When we consider the intersection of where tokens live (ledger vs. contract) and their privacy properties (shielded vs. unshielded), we get a matrix of possibilities:

Token TypeLocationPrivacyKey CharacteristicsExample Use Cases
Shielded Ledger TokensBlockchain ledgerPrivateNative privacy, maximum efficiency, UTXO-basedPrivate payments, confidential value transfer
Unshielded Ledger TokensBlockchain ledgerTransparentFull transparency, high performance, UTXO-basedNIGHT tokens, public treasuries, exchange listings
Shielded Contract TokensSmart contractsPrivateProgrammable privacy, custom logic, account-basedPrivate securities, confidential rewards
Unshielded Contract TokensSmart contractsTransparentFull programmability, ERC-20 style, complex interactionsGovernance tokens, public DeFi protocols

Each token type serves specific needs. Unshielded ledger tokens like NIGHT provide transparent, high-performance value transfer—perfect for exchanges, public treasuries, or any scenario requiring auditability. Shielded ledger tokens enable private peer-to-peer transactions with the efficiency of native blockchain operations.

Contract tokens bring programmability to both transparent and private use cases. Unshielded contract tokens work like traditional ERC-20s but benefit from Midnight's infrastructure. Shielded contract tokens open entirely new possibilities—imagine private company equity where transfers are confidential but voting rights remain verifiable.

Implications

Understanding Midnight's hybrid architecture fundamentally changes how you approach application design. Instead of being constrained by a single model's limitations, you can architect solutions that leverage each model's strengths.

Consider a decentralized exchange. Traditional DEXs on account-based chains suffer from MEV and lack privacy options. On Midnight, you could architect a hybrid solution: the order book and market-making logic live in transparent smart contracts (leveraging the account model's strengths for complex state), while actual token swaps execute as atomic UTXO transactions (leveraging parallelism and optional privacy). This isn't just theoretical—it's the kind of innovation Midnight's architecture enables.

Decisions

When building on Midnight, your first decision is often whether to use ledger tokens or contract tokens. Here's a framework for making that choice:

Choose ledger tokens when you need maximum performance, native privacy features, or simple value transfer without complex logic. The UTXO model's parallelism makes ledger tokens ideal for payment systems, remittance platforms, or any high-volume transaction scenario.

Choose contract tokens when you need programmable logic, complex state management, or integration with other smart contracts. The account model within contracts makes these perfect for DeFi protocols, gaming assets, or tokens with sophisticated distribution mechanisms.

You're not locked into one choice. A single application can use both ledger tokens for efficient value transfer and contract tokens for complex logic. This flexibility is what makes Midnight's architecture revolutionary.