Introduction
This page shows how to split a Scrypto dApp across small blueprints whose components call each other, and how to use blueprints published in other packages. Scrypto separates the concept of "smart contract" into two distinct things: blueprints (reusable templates) and components (live instances on the ledger). This separation enables a modular architecture where small, well-tested blueprints are composed into larger systems β much like how object-oriented programming uses classes and composition. The official Scrypto Design Patterns documentation recommends small blueprints, and notes that a small application can keep all its logic in one.
Separation of Concerns
Instead of building a monolithic blueprint, decompose your dApp into small blueprints with a single responsibility:
- TokenSale β handles pricing and token distribution
- Treasury β manages collected funds, fee withdrawal
- AccessControl β issues and manages badges
- PriceFeed β wraps an oracle and exposes prices to other components
Each blueprint is easier to test in isolation, reason about for security, and audit independently. Smaller blueprints are also more reusable β a DEX, a lending protocol and a DAO can each instantiate the same Treasury blueprint without changing it.
Inter-Component Calls
Components call each other's methods using their on-ledger address. A component can store another component's address in its state and invoke methods on it:
#[blueprint]
mod my_dapp {
// Treasury and PriceFeed are blueprints in the same package.
use super::price_feed::PriceFeed;
use super::treasury::Treasury;
struct MyDapp {
treasury: Global<Treasury>,
price_feed: Global<PriceFeed>,
tokens: FungibleVault,
}
impl MyDapp {
pub fn buy(&mut self, payment: Bucket) -> Bucket {
let price = self.price_feed.get_price("XRD/USD".to_string());
let owed = payment.amount() * price;
self.treasury.deposit(payment);
self.tokens.take(owed).into()
}
}
}Compiled and run under Scrypto 1.4.0 on 6 October 2026, with a Treasury holding an $XRD vault and a PriceFeed returning 2: a call to buy with 10 $XRD left 10 $XRD in the treasury and 20 tokens in the caller's account. Two details the compiler enforces: get_price takes a String, so a bare "XRD/USD" is a type error (E0308) and needs .to_string(); and the use lines are required, because without them Global<Treasury> does not resolve (E0412), although cargo flags them as unused imports.
Blueprint Reuse & the Catalog
The Scrypto Design Patterns documentation gives royalties as one reason to publish small, reusable blueprints: a developer can earn royalties when other developers use them. In October 2020 the Radix team described a Blueprint Catalog, an on-ledger registry that every published blueprint would join, so that developers could find and reuse existing blueprints rather than reimplement common patterns.
Importing External Blueprints
To use a blueprint from another package, import it by its package address and instantiate or call it. The Scrypto extern_blueprint! macro generates type-safe bindings. It goes inside the #[blueprint] module, because the attribute macro is what finds and expands it (source); written at the crate root, it fails with cannot find macro:
#[blueprint]
mod pricing_user {
extern_blueprint! {
"package_rdx1...", // the package's address on the network you deploy to
PriceFeed {
fn instantiate() -> Global<PriceFeed>;
fn get_price(&self, pair: String) -> Decimal;
}
}
struct PricingUser {
price_feed: Global<PriceFeed>,
}
impl PricingUser {
pub fn instantiate() -> Global<PricingUser> {
let price_feed = Blueprint::<PriceFeed>::instantiate();
Self { price_feed }.instantiate().prepare_to_globalize(OwnerRole::None).globalize()
}
pub fn quote(&self) -> Decimal {
self.price_feed.get_price("XRD/USD".to_string())
}
}
}This generates a type you can use in your component's state and method signatures, with full compile-time type checking. Functions listed in the block are called through Blueprint::<PriceFeed>, methods on a Global<PriceFeed>. Tested on 6 October 2026 by publishing the PriceFeed package to resim and importing it from a second package by that address: quote returned 2.
Factory Pattern
A common pattern for dApps that create multiple similar components (e.g. a DEX creating liquidity pools): write a factory blueprint whose instantiation function creates and configures child components, returning their addresses and any admin badges.
Next Steps
- Oracle Integration β bring off-ledger data in without giving up determinism
