The ResourceBuilder
The ResourceBuilder
is your utility for creating new resources. You have a number of resource creation methods to make things easy.
You can start using it like this ResourceBuilder::new_
then complete the building process using either create_with_no_initial_supply()
or mint_initial_supply(..)
.
What’s returned
It’s important to note that
create_with_no_initial_supply()
will return aResourceManager
where asmint_initial_supply(..)
will return a bucket with the created supply of resources.
New Resource Methods
Method | Arguments | Returns |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Read the Resource Behaviors article for further customization options on the builder, including:
Setting the
OwnerRole
Setting custom behaviours
Setting divisibility for fungible resources
Setting metadata
Here is an example creating a very simple fungible resource:
let my_token: FungibleBucket = ResourceBuilder::new_fungible(OwnerRole::None)
.metadata(metadata!(
init {
"name" => "My Token", locked;
"symbol" => "TKN", locked;
}
))
.divisibility(DIVISIBILITY_NONE) // No decimals allowed
.mint_initial_supply(100);
The Non-Fungible variants also require a struct of NonFungibleData
as you can see below:
// The top-level struct must derive NonFungibleData.
// Note that marking top-level fields as `#[mutable]` means that the data under
// that field can be updated by the `resource_manager.update_non_fungible_data(...)` method.
//
// All types referenced directly/indirectly also need to derive ScryptoSbor.
// To work with the Manifest Builder, we recommend all types also derive ManifestSbor.
#[derive(ScryptoSbor, ManifestSbor, NonFungibleData)]
struct GameData {
team_one: String,
team_two: String,
section: String,
seat_number: u16,
#[mutable]
promo: Option<String>,
}
#[blueprint]
mod nftblueprint {
struct NftBlueprint {
}
impl NftBlueprint {
pub fn create_game_nfts() {
ResourceBuilder::new_integer_non_fungible::<GameData>(OwnerRole::None)
.metadata(metadata! {
init {
"name" => "Mavs vs Lakers - 12/25/2023", locked;
"description" => "Tickets to the 2023 season of the Dallas Mavericks", locked;
}
)
.create_with_no_initial_supply();
}
}
}
The ResourceManager
When a resource is created on the Radix network, a “Resource Manager” with a unique address will be associated with it. This manager contains the data of this resource such as its type (fungible or non-fungible), its metadata and its supply among other things. It also allows people with the right authority to do actions on the resource like minting more tokens and updating its metadata. On this page, we will show you how to use the ResourceManager
type that Scrypto offers and the various methods you can call on it.
Methods available on ResourceManager
The ResourceManager
offers many methods that we listed in the following tables.
Fetching resource information
Method | Description |
---|---|
| Returns the metadata associated with the specified key. |
| Returns a ResourceType that is either non-fungible or fungible. |
| Returns the total supply of the resource. |
| Returns whether a token with the specified non-fungible id was minted. |
| Returns the data associated with a particular non-fungible token of this resource. |
Applying actions
Provided that the correct authority is presented (more information about this here), you can apply the following actions to a resource.
Method | Description |
---|---|
| Updates a metadata key associated with this resource. |
| Mints an amount of fungible tokens. Note: The resource must be of the fungible type. |
| Mints a non-fungible token with the specified id and data. Note: The resource must be of the non-fungible type |
| Updates a single field of the non-fungible data associated with a minted non-fungible token of the specified ID. |
Updating resource flags
More information on access rules and resource flags here.
Method | Description |
---|---|
| Sets the access rule for being able to update the |
| Locks the |
| Sets the access rule for being able to update the |
| Locks the |
| Sets the access rule for being able to update the |
| Locks the |
| Sets the access rule for being able to update the |
| Locks the |
| Sets the access rule for being able to update the |
| Locks the |
| Sets the access rule for being able to update the |
| Locks the |
| Sets the access rule for being able to update the |
| Locks the |
The owner role can be updated with set_owner_role
and lock_owner_role
.