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, part by part.
What you'll build
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.
- Initialization script — a transaction script to deploy and initialize the bank.
Each part ends with a runnable MockChain test so you can verify what you built works correctly.
Tutorial structure
Every part builds on the previous one and includes:
- What you'll build — clear objectives for the section.
- Step-by-step code — progressively building functionality.
- Try it — a MockChain test to verify your code works.
- Complete code — full code listing for reference.
Walkthrough
Part 0: Project setup
Create your project with miden new and understand the workspace structure.
Part 1: Account components
Learn #[component], Value storage, and StorageMap for managing state.
Part 2: Constants & constraints
Define constants and validate inputs with assertions.
Part 3: Asset management
Handle fungible assets with vault operations and balance tracking.
Part 4: Note scripts
Write scripts that execute when notes are consumed.
Part 5: Cross-component calls
Call account methods from note scripts via bindings.
Part 6: Transaction scripts
Write scripts for account initialization and owner operations.
Part 7: Output notes
Create P2ID notes programmatically for withdrawals.
Part 8: Complete flows
Walk through end-to-end deposit and withdraw operations.
Prerequisites
- Completed the Get started guide —
midenup,miden new, basic tooling. - Understanding of Miden concepts: accounts, notes, transactions.
- Rust programming experience.
Concepts covered
| Concept | What it does | 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] + #[note_script] | Note struct/impl pattern for scripts consumed by accounts | 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
The complete source code for this tutorial is available in the examples/miden-bank directory of the miden-tutorials repository:
git clone https://github.com/0xMiden/miden-tutorials.git
cd miden-tutorials/examples/miden-bank
Supplementary guides
Testing with MockChain
Learn to test your contracts with MockChain for local simulation.
Debugging
Interpret errors and debug common issues.
Common pitfalls
Avoid known issues and limitations.
Getting help
- Detailed technical reference: docs.miden.xyz.
- Join the Build on Miden Telegram for support.
- Review the complete code in the examples/miden-bank directory.
Ready? Start with Part 0: Project setup.