Skip to main content
Version: 0.14

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

The tutorial includes runnable tests where appropriate — some parts are setup-only or conceptual, with the first runnable test in Part 4.

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
  • Verification steps - Runnable tests, build checks, or code review
  • Complete code - Full code listing for reference

Parts Overview​

PartTopicWhat You'll Build
Part 0Project SetupCreate project with miden new
Part 1Account ComponentsBank struct with storage
Part 2Constants & ConstraintsBusiness rules and validation
Part 3Asset ManagementDeposit logic with balance tracking
Part 4Note ScriptsDeposit note for receiving assets
Part 5Cross-Component CallsHow bindings enable calls
Part 6Transaction ScriptsInitialization script
Part 7Output NotesWithdraw with P2ID output
Part 8Complete FlowsEnd-to-end verification

Tutorial Cards​

Prerequisites​

Before starting this tutorial, ensure you have:

  • Completed the Get Started 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:

ConceptDescriptionPart
#[component]Define account components with storage1
Storage TypesValue for single values, StorageMap for key-value data1
ConstantsDefine compile-time business rules2
AssertionsValidate conditions and handle errors2
Asset HandlingAdd and remove assets from account vaults3
#[note] + #[note_script]Note struct/impl pattern for scripts consumed by accounts4
Cross-Component CallsCall account methods from note scripts5
#[tx_script]Transaction scripts for account operations6
Output NotesCreate notes programmatically7

Source Code​

The complete source code for this tutorial is available in the examples/miden-bank directory of this repository:

>_ Terminal
git clone https://github.com/0xMiden/miden-tutorials.git
cd miden-tutorials/examples/miden-bank

Supplementary Guides​

These standalone guides complement the tutorial:

Getting Help​

If you get stuck during this tutorial:

Ready to build your first Miden banking application? Let's get started with Part 0: Project Setup!