- 01 Jul 2024
- 4 Minutes to read
- DarkLight
- PDF
Resource Creation in Detail
- Updated on 01 Jul 2024
- 4 Minutes to read
- DarkLight
- PDF
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(..)
.
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 |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
There are also a number of helper methods to be aware of which you will commonly chain together with one of the new_
methods above
Method | Arguments | Description |
---|---|---|
|
| The divisibility is a number between 0 and 18 and it represents the number of decimal places that this resource can be split into. For example, if you set the divisibility to 0, people will only be able to send whole amounts of that resource. Default: 18 You can also use the constants |
|
| Specify metadata on the resource. This is where you define data that will be displayed on the wallets and explorers, for example. You can find a standard for the metadata keys here. Note: You can include multiple metadata by calling this method multiple times. |
|
| Specify the |
|
| Specify the |
|
| Specify the |
|
| Specify the |
|
| Specify the |
|
| Specify the |
More details regarding how to use these methods to set authorization rules on your resources is in the Resource Behaviors coming up next.
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)
.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 |