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

Prerequisites

Concepts covered

ConceptWhat it doesPart
#[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 the miden-tutorials repository:

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

Supplementary guides

Getting help

Ready? Start with Part 0: Project setup.