This page shows how a Scrypto blueprint creates fungible and non-fungible resources, holds and moves them in vaults and buckets, and proves it holds them with proofs.
Resources
A resource is any digital asset on Radix – tokens, NFTs, badges, liquidity-pool units and so on. Radix resources are native engine primitives with built-in rules for minting, burning, transferring and access control; Scrypto Fundamentals compares them with tokens in Solidity.
There are two kinds:
Creating Fungible Resources
let my_token: Bucket = ResourceBuilder::new_fungible(OwnerRole::None)
.metadata(metadata!(
init {
"name" => "My Token", locked;
"symbol" => "MYT", locked;
}
))
.mint_initial_supply(1_000_000)
.into();This creates 1 million tokens with locked name and symbol. The : Bucket annotation is needed because mint_initial_supply returns a FungibleBucket, as it has since Scrypto v1.0.0: without it .into() has no target type, and the build stops with error E0282, type annotations needed, as soon as the variable is used. The OwnerRole::None means no one can change the resource's configuration after creation.
What is divisibility, and what is $XRD's?
Divisibility is the number of decimal places a fungible resource's amounts may carry, fixed when the resource is created. It runs from 0, whole units only, to 18, which is also what ResourceBuilder uses when none is given (constants, default). $XRD has a divisibility of 18, set in the genesis transaction that created it, so its smallest amount is 0.000000000000000001 (bootstrap.rs). The ceiling of 18 is Decimal's: every amount is a Decimal, which holds 18 decimal places (Data Types and the Runtime API).
let points: Bucket = ResourceBuilder::new_fungible(OwnerRole::None)
.divisibility(2) // amounts down to 0.01
.mint_initial_supply(1_000)
.into();
// Reading it back: None for a non-fungible resource.
let d: Option<u8> = ResourceManager::from(XRD).resource_type().divisibility(); // Some(18)The engine accepts an amount only if it is not negative and has no more decimal places than the divisibility allows (check_fungible_amount). In the simulator, minting 1.005 of a resource with divisibility 2 failed with InvalidAmount(1.005, 2); a withdrawal fails the same way, which Vault and Resource Patterns shows how to avoid. A divisibility above 18 never reaches the ledger: the builder panics, and the engine refuses one sent any other way with InvalidDivisibility (builder, engine).
Creating Non-Fungible Resources (NFTs)
#[derive(ScryptoSbor, NonFungibleData)]
pub struct Ticket {
pub event_name: String,
pub seat: u32,
#[mutable]
pub used: bool,
}
let tickets: Bucket = ResourceBuilder::new_integer_non_fungible::(OwnerRole::None)
.metadata(metadata!(
init {
"name" => "Event Ticket", locked;
}
))
.mint_initial_supply([
(IntegerNonFungibleLocalId::new(1), Ticket {
event_name: "RadFest".into(),
seat: 42,
used: false,
}),
])
.into();Fields marked #[mutable] can be updated later via the ResourceManager. Immutable fields are fixed at mint time.
Vaults and Buckets
Resources must always be inside a container:
| Container | Lifetime | Purpose |
|---|---|---|
| Vault | Permanent (on-ledger state) | Store resources between transactions |
| Bucket | Transient (single transaction) | Move resources during a transaction |
The Radix Engine fails a transaction that drops a non-empty bucket (source), so every bucket has to be emptied before the transaction ends.
// Take 10 tokens from a vault into a bucket
let bucket: Bucket = self.my_vault.take(10);
// Put them into another vault
self.other_vault.put(bucket);Typed variants (FungibleVault, NonFungibleVault, FungibleBucket, NonFungibleBucket) provide type-safe operations when you know the resource type at compile time.
Proofs
Proofs let you demonstrate ownership of a resource without transferring it – like showing an ID badge without handing it over.
// Create a proof of one admin badge held in a vault
let proof = self.admin_badge.as_fungible().create_proof_of_amount(1);
// A proof made in a blueprint comes back to you. Push it onto the
// Auth Zone, where the Radix Engine checks it against access rules
LocalAuthZone::push(proof);A Vault has no create_proof_of_all: fungible vaults prove an amount and non-fungible vaults prove specific IDs, and LocalAuthZone is where a proof goes to count towards a call. authorize_with_amount(1, || ...) does both in one step and drops the proof when the closure returns.
Proofs are central to Radix's authorization model. Protected methods check for proofs in the caller's Auth Zone.
ResourceManager
Every resource has a ResourceManager – the on-ledger controller for that resource type. Use it to mint, burn, query supply, and update NFT data:
// Mint more tokens (if resource was created with mint role)
let new_tokens: Bucket = self.resource_manager.mint(500);
// Get total supply
let supply: Decimal = self.resource_manager.total_supply().unwrap();
// Update mutable NFT data
self.resource_manager.update_non_fungible_data(
&nft_id,
"used",
true,
);Can a blueprint mint zero tokens?
Yes. mint(0) on a fungible resource succeeds and returns an empty bucket, provided the caller holds the minter role. Before minting, the engine checks only that the amount is not negative, fits the resource's divisibility, and is no more than a per-mint ceiling of about 5.7 × 1027 tokens; zero passes all three (check_mint_amount, mint).
A zero mint still emits a MintFungibleResourceEvent with an amount of 0, and adds 0 to the tracked total supply. In the simulator, a blueprint's mint(0) returned a bucket holding 0, its receipt carried the MintFungibleResourceEvent, and the total supply stayed at 0. $XRD itself began this way: the genesis transaction created it with an initial supply of 0, which goes through the same check (bootstrap.rs). To refuse a zero mint, a blueprint has to check the amount itself.
Next Steps
- Authorization and Access Rules – decide who is allowed to mint, withdraw, and update what
