Building Unshielded Token dApps with Compact and React on Midnight
These articles are AI-generated summaries. Please check the original sources for full details.
Building an Unshielded Token dApp with UI on Midnight
Midnight provides unshielded tokens for developers requiring on-chain verifiability without the computational overhead of ZK proofs. This system allows for public governance and loyalty points using a domain-specific language called Compact to store balances in public ledger state.
Why This Matters
While privacy is a core feature of Midnight, the technical reality is that not all assets require shielded privacy; unshielded tokens offer a path for public ledgers, governance, and demo applications. By choosing unshielded tokens, developers avoid the ZK circuit overhead, resulting in lower DUST fees and faster transaction confirmation times compared to private assets.
Key Insights
- Compact smart contracts use the ‘ledger’ keyword to store public state, such as a Map of addresses to Uint<128> balances (Midnight, 2026).
- Unshielded tokens are defined as having public on-chain balances and visible transfer amounts, whereas shielded tokens require ZK proofs for every transaction.
- The Midnight JS SDK (@midnight-ntwrk/midnight-js-*) provides WalletBuilder and NodeZkConfigProvider to integrate TypeScript applications with the prover and indexer.
- Local development environments for Midnight require a Docker stack running four key services: Node (9944), Indexer (8088), Prover (6300), and Explorer (3000).
- The ‘own_public_key()’ function in Compact circuits is critical for access control, ensuring only the contract owner can execute minting operations.
Working Examples
Compact smart contract snippet for an unshielded token with minting logic.
pragma language_version >= 0.14.0;
import CompactStandardLibrary;
export ledger total_supply: Counter;
export ledger balances: Map<Bytes<32>, Uint<128>>;
export ledger owner: Bytes<32>;
export circuit mintUnshielded(recipient: Bytes<32>, amount: Uint<128>): [] {
assert own_public_key() == ledger.owner "Only the contract owner can mint";
assert amount > 0 "Amount must be positive";
const current_balance: Uint<128> = ledger.balances.lookup(recipient).value_or(0);
ledger.balances.insert(recipient, current_balance + amount);
ledger.total_supply.increment(amount);
}
TypeScript function to deploy the unshielded token contract using Midnight JS.
export async function deployTokenContract(wallet: any, name: string, symbol: string, decimals = 6) {
const encodeStr = (s: string, len: number) => Buffer.from(s.padEnd(len, '\0').slice(0, len));
const contract = new CompactContract.UnshieldedToken(
encodeStr(name, 32),
encodeStr(symbol, 8),
BigInt(decimals)
);
const deployTx = await contract.deploy(wallet, {});
await deployTx.submit();
return { contract, address: deployTx.contractAddress };
}
Practical Applications
- Use Case: Public governance tokens where individual holdings must be auditable by all participants. Pitfall: Using unshielded tokens for private business payments, which exposes sensitive financial data on the public ledger.
- Use Case: Loyalty points for retail apps that prioritize lower DUST fees and faster proof times over privacy. Pitfall: Forgetting to include an ‘amount > 0’ assertion in the transfer circuit, potentially allowing zero-value spam transactions.
References:
Continue reading
Next article
Critical Security Flaw in OpenClaw AI: Unauthenticated Sandbox Access via Middleware Misconfiguration
Related Content
Mastering Shielded Token Lifecycles with Midnight's Compact Language
Implement private value movement in Midnight apps by building a shielded token lifecycle with mint, transfer, and burn operations using Compact.
Building Advanced Django-Unfold Dashboards: Custom Models, Filters, and KPIs
A technical guide to building professional Django admin dashboards using Django-Unfold, featuring custom KPI cards and dynamic back-office navigation.
Building Unshielded Token Smart Contracts on Midnight Network
Develop unshielded token contracts on the Midnight network using the UTXO model and CompactStandardLibrary for transparent public fund management.