DEV Community

BossChaos
BossChaos

Posted on

Building a Governance Token dApp on Midnight

Complete Source Code: GitHub Repository

Network: Midnight Preprod

Stack: Compact + TypeScript + React + Vite


Introduction

Midnight is famous for privacy-first smart contracts using zero-knowledge proofs. But not everything needs to be private. Sometimes you want transparent, publicly verifiable transactions — like community governance tokens, loyalty points, or public reward systems.

In this tutorial, we will build a complete unshielded token dApp on Midnight with role-based minting, transfer memos, and balance snapshots for governance voting.


Why Unshielded Tokens

Unshielded tokens are perfect for governance because transparency builds trust. Unlike shielded tokens that hide balances and transfers behind ZK proofs, unshielded tokens offer lower gas costs and faster confirmation times.

Use cases include governance voting, public reward systems, and loyalty programs where auditability matters more than privacy.


The Smart Contract

Our GovernanceToken contract implements three key features for decentralized governance:

Role-Based Minting

Instead of a single minter, the contract uses a minter role system. The deployer can grant or revoke minting permissions to other addresses, enabling multi-sig governance or DAO-controlled token issuance.

Transfer with Memo

Every transfer supports an optional 64-byte memo field. This creates an on-chain audit trail useful for payment references, vote tracking, and compliance reporting.

Balance Snapshots

For governance voting, you need to know a user balance at a specific point in time. Snapshots lock in balances so users cannot game the system by transferring tokens after a vote is announced.


TypeScript Integration

The TypeScript layer connects the React frontend to the Midnight blockchain through the DApp Connector API. It handles wallet building, contract deployment, and transaction submission.

Key components include the WalletBuilder for seed-based wallet creation, the IndexerProvider for balance queries, and the NodeZkConfigProvider for proof generation.


Building the UI

The React frontend provides four main panels:

  1. WalletConnect handles wallet discovery and connection state management
  2. BalanceDisplay shows token balances with real-time refresh from the indexer
  3. MintPanel provides a form for authorized minters to issue new tokens
  4. TransferPanel enables token transfers with memo field support

The UI uses TailwindCSS for a dark theme optimized for developer workflows.


Testing and Deployment

Before going live, test all contract functions against the Midnight local Docker stack. The deployment script handles wallet initialization, contract compilation, and transaction submission.

Run the integration test suite to verify minting permissions, transfer memo encoding, and snapshot accuracy before deploying to preprod.


Full source code available at https://github.com/BossChaos/midnight-governance-token

Top comments (0)