Resource Creation in Detail

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 a ResourceManager where as mint_initial_supply(..) will return a bucket with the created supply of resources.

New Resource Methods

Method

Arguments

Returns

new_fungible()

owner_role : OwnerRole

InProgressResourceBuilder<FungibleResourceType>

new_string_non_fungible()

  • owner_role : OwnerRole

  • <NonFungibleData>

InProgressResourceBuilder<NonFungibleResourceType<StringNonFungibleLocalId, D>>

new_integer_non_fungible()

  • owner_role : OwnerRole

  • <NonFungibleData>

InProgressResourceBuilder<NonFungibleResourceType<IntegerNonFungibleLocalId, D>>

new_bytes_non_fungible()

  • owner_role : OwnerRole

  • <NonFungibleData>

InProgressResourceBuilder<NonFungibleResourceType<BytesNonFungibleLocalId, D>>

new_ruid_non_fungible()

  • owner_role : OwnerRole

  • <NonFungibleData>

InProgressResourceBuilder<NonFungibleResourceType<RUIDNonFungibleLocalId, D>>

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

get_metadata(key)

Returns the metadata associated with the specified key.

resource_type()

Returns a ResourceType that is either non-fungible or fungible.

total_supply()

Returns the total supply of the resource.

non_fungible_exists(NonFungibleLocalId)

Returns whether a token with the specified non-fungible id was minted.

get_non_fungible_data(NonFungibleLocalId)

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

set_metadata(key, value)

Updates a metadata key associated with this resource.

mint(amount)

Mints an amount of fungible tokens.

Note: The resource must be of the fungible type.

mint_non_fungible(&id, data)

Mints a non-fungible token with the specified id and data.

Note: The resource must be of the non-fungible type

update_non_fungible_data(&id, field_name, new_data)

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

set_mintable(access_rule)

Sets the access rule for being able to update the mintable flag.

lock_mintable()

Locks the mintable flag.

set_burnable(access_rule)

Sets the access rule for being able to update the burnable flag.

lock_burnable()

Locks the burnable flag.

set_withdrawable(access_rule)

Sets the access rule for being able to update the withdrawable flag.

lock_withdrawable()

Locks the withdrawable flag.

set_depositable(access_rule)

Sets the access rule for being able to update the depositable flag.

lock_depositable()

Locks the depositable flag.

set_recallable(access_rule)

Sets the access rule for being able to update the recallable flag.

lock_recallable()

Locks the recallable flag.

set_updatable_metadata(access_rule)

Sets the access rule for being able to update the updateable_metadata flag.

lock_updatable_metadata()

Locks the updateable_metadata flag.

set_updatable_non_fungible_data(access_rule)

Sets the access rule for being able to update the updateable_non_fungible_data flag.

lock_updatable_non_fungible_data()

Locks the updateable_non_fungible_data flag.

The owner role can be updated with set_owner_role and lock_owner_role.

Related Rust docs