Skip to main content

On This Page

Building Unshielded Token Smart Contracts on Midnight Network

2 min read
Share

These articles are AI-generated summaries. Please check the original sources for full details.

How to build an unshielded token smart contract and UI on Midnight network

The Midnight network provides native circuits for unshielded tokens to support public visibility in decentralized applications. These tokens utilize a UTXO model and require 32-byte domain separators to uniquely identify token types within a single contract.

Why This Matters

Developers must distinguish between shielded and unshielded tokens based on the need for selective visibility versus full public auditability. Unlike account-based ERC-20 tokens, Midnight’s unshielded assets rely on the UTXO model where the token contract only intervenes when it is the direct sender or recipient of funds, requiring a paradigm shift in transaction construction.

Key Insights

  • The mintUnshieldedToken circuit requires a 32-byte domain separator to derive a unique token ‘color’ for contract-wide identification (Midnight Network, 2026).
  • User-to-user transfers are signed directly by the client rather than passing through the token contract’s sendUnshielded circuit.
  • Midnight’s unshielded tokens utilize a UTXO model, requiring developers to move away from the account-based logic found in Ethereum’s ERC-20 standard.
  • The Compact CLI compiles smart contract logic into artifacts used by the Vite frontend to interact with the Midnight DApp connector.
  • Frontend providers must be split into a WalletProvider for balancing transactions and a MidnightProvider for submission to the network via a ConnectedAPI.

Working Examples

A basic unshielded token contract implementation in Compact showing the mint circuit.

pragma language_version >= 0.16; import CompactStandardLibrary; export ledger domainSep: Bytes<32>; constructor() { domainSep = "aaaaAAAAaaaaAAAAaaaaAAAAaaaaAAAA"; } export circuit mint(value: Uint<64>, recipient: UserAddress): [] { mintUnshieldedToken(domainSep, disclose(value), disclose(right<ContractAddress, UserAddress>(disclose(recipient)))); }

Practical Applications

  • Public foundation treasuries use unshielded tokens to maintain a transparent record of all fund movements for auditing purposes. Pitfall: Using unshielded tokens for payroll can compromise employee privacy because all transactions are fully visible.
  • Charity platforms leverage the receiveUnshielded circuit to accept public donations directly into a contract. Pitfall: Incorrectly deriving the token ‘color’ using tokenType can lead to mismatches between minted assets and ledger entries.

References:

Continue reading

Next article

Why Stack Overflow Migrated from Ingress-NGINX to Istio Gateway API

Related Content