Create, understand, and run the Hello Token blueprint—your first Scrypto smart contract.
Create Your Package
A package is a container for one or more blueprints. Let's create one:
Terminal
scrypto new-package hello_token
cd hello_tokenThis creates a standard Rust project structure:
Project Structure
hello_token/
├── src/
│ └── lib.rs ← Your blueprint code
├── tests/
│ └── lib.rs ← Tests
└── Cargo.toml ← Package configurationUnderstanding the Template
Open src/lib.rs. The template gives you a working blueprint:
src/lib.rs
use scrypto::prelude::*;
#[blueprint]
mod hello_token {
struct HelloToken {
// A vault to permanently store tokens
sample_vault: Vault,
}
impl HelloToken {
// Function: Creates a new HelloToken component
pub fn instantiate() -> Global<HelloToken> {
// Create 1000 "HelloToken" tokens
let my_bucket: Bucket = ResourceBuilder::new_fungible(OwnerRole::None)
.metadata(metadata! {
init {
"name" => "HelloToken", locked;
"symbol" => "HT", locked;
}
})
.mint_initial_supply(1000)
.into();
// Store tokens in a vault and create the component
Self {
sample_vault: Vault::with_bucket(my_bucket),
}
.instantiate()
.prepare_to_globalize(OwnerRole::None)
.globalize()
}
// Method: Returns 1 token to whoever calls this
pub fn free_token(&mut self) -> Bucket {
self.sample_vault.take(1)
}
}
}Let's break this down piece by piece:
Key Concepts
Blueprint
A blueprint is a template—like a class in OOP. It defines what a component will look like and how it behaves, but isn't "live" on the ledger itself.
Component
A component is an instance of a blueprint. When you call instantiate(), you create a component with its own address and state. Think of it like creating an object from a class.
Vault
A vault is permanent storage for resources (tokens). Resources in a vault stay there until explicitly taken out. Every component that holds tokens needs a vault.
Bucket
A bucket is a temporary container for moving resources. When a method returns tokens, they travel in a bucket. Buckets must be emptied before a transaction ends.
Code Walkthrough
1. The struct defines component state
struct HelloToken {
sample_vault: Vault, // This vault holds all our tokens
}Every blueprint has a struct. The fields become the component's persistent state. Here we have one vault that will hold our tokens.
2. Creating a resource
let my_bucket: Bucket = ResourceBuilder::new_fungible(OwnerRole::None)
.metadata(metadata! {
init {
"name" => "HelloToken", locked;
"symbol" => "HT", locked;
}
})
.mint_initial_supply(1000)
.into();ResourceBuilder creates new token types. This creates a fungible (divisible) token with a name and symbol, mints 1000 of them, and returns them in a bucket.
3. Creating the component
Self {
sample_vault: Vault::with_bucket(my_bucket),
}
.instantiate()
.prepare_to_globalize(OwnerRole::None)
.globalize()This chain creates the component: initialize state → instantiate → make it global (accessible by address). The tokens are stored in the vault.
4. A method that returns tokens
pub fn free_token(&mut self) -> Bucket {
self.sample_vault.take(1)
}&mut self means this method can modify the component's state.take(1) removes 1 token from the vault and returns it in a bucket.
Build and Run
Let's see it in action using the simulator:
Terminal
# Build the package
scrypto build
# Reset the simulator (fresh start)
resim reset
# Create an account (you need one to deploy)
resim new-account
# Save the Account component address shown
# Publish the package
resim publish .
# Save the Package address shown
# Instantiate a component
resim call-function <PACKAGE_ADDRESS> HelloToken instantiate
# Save the Component address shown
# Call the free_token method
resim call-method <COMPONENT_ADDRESS> free_token
# Check your account - you should have 1 HelloToken!
resim show <ACCOUNT_ADDRESS>✅ You just:
Created a new token type (HelloToken)
Deployed a blueprint to the simulator
Instantiated a component that holds 1000 tokens
Called a method that gave you a token
Functions vs Methods
Functions
• Called on the blueprint
• No
selfparameter• Used to instantiate components
•
call-functionin resim
pub fn instantiate() -> Global<HelloToken>Methods
• Called on a component
• Has
&selfor&mut self• Used to interact with component state
•
call-methodin resim
pub fn free_token(&mut self) -> Bucket🧪 Try It Yourself
Modify the blueprint to:
Change the token name to your own name
Create 10,000 tokens instead of 1,000
Make
free_tokengive out 5 tokens instead of 1
After each change: scrypto build → resim reset → redeploy
Summary
✓ Blueprints are templates; components are instances
✓ Vaults store resources permanently; buckets move them temporarily
✓ ResourceBuilder creates new token types
✓ Functions create components; methods interact with them
Connect your wallet to join the discussion.
