Fungible Resources

On this page, you will learn how to create your first resource using Scrypto. Creating resources with Scrypto is very simple since they are handled at the platform-level rather than at the code-level like many other smart-contract platforms.

The ResourceBuilder

The ResourceBuilder is a Scrypto interface that we use to create fungible and non-fungible resources. Let’s take a look at an example:

let my_token: FungibleBucket = ResourceBuilder::new_fungible(OwnerRole::None)
    .metadata(metadata!(
        init {
            "name" => "My Token", locked;
            "symbol" => "TKN", locked;
        }
    ))
  .mint_initial_supply(100);

Creating a fungible resource start by calling ResourceBuilder::new_fungible(). You may choose configure a resource OWNER with OwnerRole:: to set permissions within the ResourceManager (even after the resource has been created). Specifying to None will prevent you from ever re-configuring the resource from the ResourceManager later. You are then able to pre-configure the resource however you like by the available methods of the ResourceBuilder. In our example, we configure the resource’s metadata by calling the .metadata method with a name “MyToken“ and symbol “TKN“.

However, with this example, instead of creating the resource with an initial supply, we will instead call .create_with_no_initial_supply(). This will result in returning us a ResourceManager type instead of a Bucket type.

Let’s look at an example:

let my_token: ResourceManager = ResourceBuilder::new_fungible(OwnerRole::None)
    .metadata(metadata!(
        init {
            "name" => "My Token", locked;
            "symbol" => "TKN", locked;
        }
    ))
  .create_with_no_initial_supply();

Because

When we are done configuring the token, we are calling the .mint_initial_supply(amount) which will create the resource on the network and return a Bucket containing the initial tokens.

In this example, the token is not very useful because we do not provide the authorization rules for minting new tokens of this particular `ResourceAddress`. This means that there will never be any token of this `ResourceAddress`. To learn how to set resource action rules read xref:access-control/restricting-resource-actions.adoc[this page].

ResourceBuilder Methods

Here are the different methods you can call to configure your resource using the ResourceBuilder:

Method

Description

.divisibility(number)

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

.metadata(metadata!)

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.

.mint_roles(mint_roles!)

Specify the AccessRule for MintRoles to provide permission to mint tokens.

.burn_roles(burn_roles!)

Specify the AccessRule for BurnRoles to provide permission to burn tokens.

.withdraw_roles(withdraw_roles!)

Specify the AccessRule for WithdrawRoles to provide permission to withdraw tokens from a Vault.

.deposit_roles(deposit_roles!)

Specify the AccessRule for DepositRoles to provide permission to deposit tokens to a Vault.

.recall_roles(recall_roles!)

Specify the AccessRule for RecallRoles to provide permission to freeze tokens.

.freezer_roles(freezer_roles!)

Specify the AccessRule for FreezeRoles to provide permission to freeze tokens.

For more information on how to use the methods to set authorization rules on your resources take a look at the page here.