Agent skill
compact-core:contract-patterns
Use when implementing common Compact contract patterns such as voting systems, escrow, token transfers, access control, auctions, registries, or when looking for reusable contract templates and design patterns for Midnight blockchain development.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/contract-patterns
SKILL.md
Contract Patterns
Reusable Compact contract patterns and best practices for Midnight development
Overview
This skill provides a comprehensive catalog of Compact contract patterns for the Midnight blockchain. Patterns range from simple building blocks to comprehensive multi-contract systems.
Pattern Categories
-
Simple Patterns (~10 focused examples)
- Basic state management
- Access control primitives
- Time-based logic
- Cryptographic commitments
-
Deep-Dive Implementations (3 comprehensive systems)
- Private Voting System
- Multi-Party Token Escrow
- Role-Based Access Registry
Quick Navigation
Simple Patterns
| Pattern | File | Use Case |
|---|---|---|
| Counter | examples/simple/counter.compact |
Basic state increments |
| Ownership | examples/simple/ownership.compact |
Single-owner control |
| Time Lock | examples/simple/time-lock.compact |
Delayed execution |
| Whitelist | examples/simple/whitelist.compact |
Membership verification |
| Rate Limit | examples/simple/rate-limit.compact |
Action throttling |
| Multi-Sig | examples/simple/multi-sig.compact |
N-of-M approvals |
| Pausable | examples/simple/pausable.compact |
Emergency stops |
| Upgradeable | examples/simple/upgradeable.compact |
Logic migration |
| Fee Collector | examples/simple/fee-collector.compact |
Payment handling |
| Random Selection | examples/simple/random-selection.compact |
Commit-reveal randomness |
Deep-Dive Systems
| System | Directory | Description |
|---|---|---|
| Private Voting | examples/deep-dives/private-voting/ |
Complete anonymous voting with ZK proofs |
| Token Escrow | examples/deep-dives/token-escrow/ |
Multi-party custody with conditions |
| Access Registry | examples/deep-dives/access-registry/ |
Role-based access with Merkle proofs |
References
- Pattern Catalog - Quick reference for all patterns
- Private Voting Deep-Dive - Voting system architecture
- Token Escrow Deep-Dive - Escrow implementation guide
- Access Registry Deep-Dive - Role-based access patterns
Usage Examples
Finding a Pattern
"Show me the counter pattern"
→ Read examples/simple/counter.compact
Understanding Complex Systems
"How do I implement private voting?"
→ Read references/private-voting.md then explore examples/deep-dives/private-voting/
Adapting Patterns
"I need time-locked multi-sig"
→ Combine time-lock.compact + multi-sig.compact patterns
Best Practices
- Start Simple: Use simple patterns as building blocks
- Understand Privacy: Know what's public vs private in each pattern
- Test Thoroughly: Each pattern includes test considerations
- Combine Carefully: When mixing patterns, verify privacy guarantees
- Document Intent: Add comments explaining business logic
Dependencies
All patterns use standard library imports:
import CompactStandardLibrary;
Some advanced patterns may require additional imports:
import CompactStandardLibrary.Merkle;
import CompactStandardLibrary.Crypto;
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?