Building a Bank with Miden Rust
Welcome to the Miden Rust Compiler Tutorial! This hands-on guide teaches you how to build smart contracts on Miden using Rust by walking through a complete banking application.
What You'll Build
You'll create a banking system consisting of:
- Bank Account Component: A smart contract that manages depositor balances and vault operations
- Deposit Note: A note script that processes deposits into the bank
- Withdraw Request Note: A note script that requests withdrawals from the bank
- Initialization Script: A transaction script to deploy and initialize the bank
Each part ends with a runnable MockChain test that verifies what you built works correctly.
Tutorial Structure
This tutorial is designed for hands-on learning. Each part builds on the previous one, and every part includes:
- What You'll Build - Clear objectives for the section
- Step-by-step code - Progressively building functionality
- Try It section - A MockChain test to verify your code works
- Complete code - Full code listing for reference
Parts Overview
| Part | Topic | What You'll Build |
|---|---|---|
| Part 0 | Project Setup | Create project with miden new |
| Part 1 | Account Components | Bank struct with storage |
| Part 2 | Constants & Constraints | Business rules and validation |
| Part 3 | Asset Management | Deposit logic with balance tracking |
| Part 4 | Note Scripts | Deposit note for receiving assets |
| Part 5 | Cross-Component Calls | How bindings enable calls |
| Part 6 | Transaction Scripts | Initialization script |
| Part 7 | Output Notes | Withdraw with P2ID output |
| Part 8 | Complete Flows | End-to-end verification |
Tutorial Cards
Prerequisites
Before starting this tutorial, ensure you have:
- Completed the Quick Start guide (familiarity with
midenup,miden new, basic tooling) - Basic understanding of Miden concepts (accounts, notes, transactions)
- Rust programming experience
This tutorial assumes no prior experience with the Miden Rust compiler. We'll explain each concept as we encounter it.
Concepts Covered
This tutorial covers the following Miden Rust compiler features:
| Concept | Description | Part |
|---|---|---|
#[component] | Define account components with storage | 1 |
| Storage Types | Value for single values, StorageMap for key-value data | 1 |
| Constants | Define compile-time business rules | 2 |
| Assertions | Validate conditions and handle errors | 2 |
| Asset Handling | Add and remove assets from account vaults | 3 |
#[note_script] | Scripts that execute when notes are consumed | 4 |
| Cross-Component Calls | Call account methods from note scripts | 5 |
#[tx_script] | Transaction scripts for account operations | 6 |
| Output Notes | Create notes programmatically | 7 |
Source Code Repository
The complete source code for this tutorial is available in the miden-bank repository. You can clone it to follow along or reference the implementation:
git clone https://github.com/keinberger/miden-bank.git
cd miden-bank
Supplementary Guides
These standalone guides complement the tutorial:
- Testing with MockChain - Learn to test your contracts
- Debugging - Troubleshoot common issues
- Common Pitfalls - Avoid known gotchas
Getting Help
If you get stuck during this tutorial:
- Check the Miden Docs for detailed technical references
- Join the Build On Miden Telegram community for support
- Review the complete code in the miden-bank repository
Ready to build your first Miden banking application? Let's get started with Part 0: Project Setup!