---
title: "2. Your First Blueprint"
url: "https://radix.wiki/developers/getting-started/02-first-blueprint"
version: "1.3.0"
updated: 2026-08-19
last_verified: 2026-08-18
license: CC-BY-4.0
license_url: "https://creativecommons.org/licenses/by/4.0/"
---

# 2. Your First Blueprint

## Overview

In this tutorial you'll build a **Gumball Machine** – a simple component that sells gumball tokens for XRD. Along the way you'll learn the core [Scrypto](/developers/scrypto/01-fundamentals) concepts: [blueprints, components, resources, and vaults](/developers/scrypto/01-fundamentals).

## Create a Package

A **package** is the deployment unit in [Scrypto](/developers/scrypto/01-fundamentals) – it contains one or more [blueprints](https://docs.radixdlt.com/docs/blueprints-and-components).

```bash
scrypto new-package gumball_machine
cd gumball_machine
```

This creates:

```
gumball_machine/
├── Cargo.toml            # Dependencies
├── Cargo.lock            # Pinned dependency versions
├── rust-toolchain.toml   # Rust channel and components for this package
├── .gitignore
├── src/
│   └── lib.rs            # Blueprint code
└── tests/
    └── lib.rs            # Tests
```

The generated `rust-toolchain.toml` is worth opening first: it pins the Rust channel this package builds with, and [which channel you get depends on the `radix-clis` version that generated it](/developers/getting-started/01-install-scrypto).

## Write the Blueprint

Replace `src/lib.rs` with the following. Each section is explained below.

```rust
use scrypto::prelude::*;

#[derive(ScryptoSbor)]
pub struct Status {
    pub price: Decimal,
    pub amount: Decimal,
}

#[blueprint]
mod gumball_machine {
    struct GumballMachine {
        gum_resource_manager: ResourceManager,
        gumballs: Vault,
        collected_xrd: Vault,
        price: Decimal,
    }

    impl GumballMachine {
        pub fn instantiate(price: Decimal) -> Global {
            let gumballs = ResourceBuilder::new_fungible(OwnerRole::None)
                .metadata(metadata!(
                    init {
                        "name" => "Gumball", locked;
                        "symbol" => "GUM", locked;
                    }
                ))
                .mint_initial_supply(100)
                .into();

            Self {
                gum_resource_manager: gumballs.resource_manager(),
                gumballs: Vault::with_bucket(gumballs),
                collected_xrd: Vault::new(XRD),
                price,
            }
            .instantiate()
            .prepare_to_globalize(OwnerRole::None)
            .globalize()
        }

        pub fn buy_gumball(&mut self, mut payment: Bucket) -> (Bucket, Bucket) {
            let cost = self.price.clone();
            let our_share = payment.take(cost);
            self.collected_xrd.put(our_share);
            (self.gumballs.take(1), payment)
        }

        pub fn get_status(&self) -> Status {
            Status {
                price: self.price.clone(),
                amount: self.gumballs.amount(),
            }
        }
    }
}
```

### Key Concepts

- **Blueprint** – a template (like a class). The `#[blueprint]` macro exposes it to the [Radix Engine](/contents/tech/core-protocols/radix-engine).
- **Component** – a live instance of a blueprint, created by `instantiate()`.
- **Resource** – a first-class digital asset. `[ResourceBuilder](https://docs.radixdlt.com/docs/resources)` creates a new fungible token ("Gumball").
- **Vault** – permanent on-ledger storage for resources. Components hold assets in [vaults](https://docs.radixdlt.com/docs/buckets-and-vaults).
- **Bucket** – a transient container for moving resources between vaults during a transaction.

Notice there is no balance tracking or transfer logic – the [Radix Engine handles asset management natively](/developers/scrypto/01-fundamentals).

## Build

```bash
scrypto build
```

This compiles to [WebAssembly](https://webassembly.org) at `target/wasm32-unknown-unknown/release/gumball_machine.wasm`.

On macOS this stops in `blst` without the two compiler variables from [Installing Scrypto](/developers/getting-started/01-install-scrypto).

## Test with resim

`resim` is the [Radix Engine Simulator](https://docs.radixdlt.com/docs/resim-radix-engine-simulator) – a local ledger you can use without connecting to any network.

```bash
# Reset the simulator
resim reset

# Create a test account (saves address to $account)
resim new-account

# Publish the package
resim publish .
# Note the package address in the output

# Instantiate a GumballMachine with price = 5 XRD
resim call-function  GumballMachine instantiate 5
# Note the component address in the output

# Buy a gumball by sending 10 XRD
resim call-method  buy_gumball "10,resource_sim1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxakj8n3"

# Check your account
resim show
```

You should see GUM tokens in your account and 5 XRD change returned.

Handy resim commands

`resim show ` – inspect any entity. `resim new-token-fixed 1000` – create test tokens. `resim reset` – wipe and start fresh.

## Next Steps

- [Deploy to Stokenet](/developers/getting-started/03-deploying) – publish your package on the public testnet
- [Scrypto Fundamentals](/developers/scrypto/01-fundamentals) – deeper dive into the [asset-oriented](/contents/tech/core-concepts/asset-oriented-programming) model
- [Testing Scrypto Blueprints](/developers/scrypto/05-testing-scrypto) – write proper unit and integration tests

## External Links

- [Official Gumball Machine tutorial](https://docs.radixdlt.com/docs/learning-to-build-a-gumball-machine)
- [resim documentation](https://docs.radixdlt.com/docs/resim-radix-engine-simulator)
- [Official Scrypto examples](https://github.com/radixdlt/official-examples)
