This directory contains smart contract and deployment scripts for Miden.xyz by Heimlabs.com.
The contracts in this repository are written in Miden Assembly (MASM) and deployed using the Miden client. These contracts demonstrate core functionality of the Miden rollup and can be interacted with through web applications.
A simple counter contract that demonstrates basic state management on Miden.
Location: masm/accounts/counter.masm
Functions:
get_count()- Returns the current counter valueincrement_count()- Increments the counter by 1
Features:
- Single storage slot for counter value
- Public storage mode
- Immutable code account type
- Rust (latest stable version)
- Cargo package manager
-
Navigate to the contracts directory:
cd contracts -
Install dependencies:
cargo build --release
Run the deployment script to create and deploy the counter contract to Miden testnet:
cargo run --releaseThis command will:
- Initialize a Miden client connected to testnet
- Compile the counter contract from MASM source
- Deploy the contract to the network
- Execute a test increment transaction
- Output the contract ID (Bech32 format)
Latest block: 12345
[STEP 1] Creating counter contract.
counter_contract commitment: ...
counter_contract id: ...
counter_contract storage: ...
[STEP 2] Call Counter Contract With Script
View transaction on MidenScan: https://testnet.midenscan.com/tx/...
Counter contract id: mtst1arjemrxne8lj5qz4mg9c8mtyxg954483
Copy the contract ID from the output (e.g., mtst1arjemrxne8lj5qz4mg9c8mtyxg954483) and use it in your web application configuration.
contracts/
├── src/main.rs # Deployment and testing script
├── masm/
│ ├── accounts/
│ │ └── counter.masm # Counter contract definition
│ └── scripts/
│ └── counter_script.masm # Transaction script for incrementing
├── Cargo.toml # Rust dependencies
├── store.sqlite3 # Local state store (generated)
└── keystore/ # Account keys (generated)
- Create your MASM contract file in
masm/accounts/ - Add compilation logic to
src/main.rs - Update the deployment script as needed
The main script includes a test transaction that demonstrates contract functionality. Modify the script in src/main.rs to test your contracts.
These contracts are designed to work with the companion web application in the webapp/ directory. The web app can interact with deployed contracts using the contract IDs obtained from running the deployment script.