02 Getting started with Scrypto
2.5 Component Modules
Now that you have a more tangible feel of how blueprints and components work, there’s one more concept we should briefly run through. In Chapter 2.3: Anatomy of a Blueprint, we discussed a bit on the globalizing process of a component. The globalization process is a preparatory step where, in a way, you can think about how you want to introduce your global component to the world. During this process you can choose to configure a “component owner” and/or additional modules that may come with a global component. Modules are add-ons which you can attach to a global component which modifies how it can be interacted with by users of the network. Currently, there are three modules which you can choose to configure with your global component: Metadata, Roles, and Royalty.
//Component Owner
The concept of an entity owner(s) (and within it, a component owner), is something we’ll explore more in Chapter 4: Introduction to Auth, but it’s worth understanding the general idea of it. The crux is that global entities (such as packages, components, and resources) in the Radix Network have owners and entity owners have certain configuration privileges of the entity it owns. Particularly, by setting the component owner, you can have the ability to continue to configure component modules after the component has been globalized. Not configuring a component owner will prevent you from re-configuring component modules defined in the blueprint - or completely disable it if component modules are not set up within the blueprint.
//Metadata Module
Metadata modules are the exception. By default, a global component comes with a metadata module, whether you choose to configure it or not. However, choosing not to configure it at all will simply attach empty metadata entries to your component. So long as you configure a component owner, you can always decide to update the metadata module of your component at a later point. Otherwise, the metadata module will be locked from being updated.
Self { sample_vault: Vault::with_bucket(my_bucket),}.instantiate().prepare_to_globalize(OwnerRole::Updatable(rule!(require(admin_badge)))).metadata(metadata!( init { "name" => "Hello Component", locked; "description" => "Get your free Hello Token with this component!", locked; })).globalize()//Royalty Module
Components can have royalties enabled where royalties can be charged in either XRD or USD for chosen method calls. You may specify the amounts which will be charged for the configured method call or set it as
Free. Royalties will be collected within a vault in your component which you can collect if you’ve configured a component owner or another designated royalty claimer.Self { sample_vault: Vault::with_bucket(my_bucket),}.instantiate().prepare_to_globalize(OwnerRole::Updatable(rule!(require(admin_badge)))).enable_component_royalties( component_royalties!( init { free_token => Xrd(dec!(1)), locked; })).globalize()//RoleAssignment Module
This module enables auth configuration within your component to restrict selected method calls to designated roles that’s been assigned by you. This enables you to set up sensitive method calls where you may not want just about anyone to call such as the ability to claim royalty fees the component has earned.
Self { sample_vault: Vault::with_bucket(my_bucket),}.instantiate().prepare_to_globalize(OwnerRole::Updatable(rule!(require(admin_badge)))).roles( roles!( admin => rule!(require(admin_badge));)).globalize()