Skip to main content
Version: 0.13 (unstable)

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

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 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:

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_script]Scripts that execute when notes are consumed4
Cross-Component CallsCall account methods from note scripts5
#[tx_script]Transaction scripts for account operations6
Output NotesCreate notes programmatically7

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:

>_ Terminal
git clone https://github.com/keinberger/miden-bank.git
cd 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!