src/lib.rs
is where you will write your package's codetests/lib.rs
is where you will write the unit tests for your blueprintsCargo.toml
is your package's manifest. It allows you to set a name, a version and specify the Rust dependenciessrc/lib.rs
.lib.rs
file defines your package. Typically you will find a single blueprint!
section in this file. (It is possible to include other blueprints defined in other files within this src
directory using the mod
declaration but the details are beyond the scope of this tutorial.)blueprint!
macro defines a code template that can be published on the ledger. It has two sections: one that defines the data that generated components will have access to and one that defines the functions and methods.struct
section defines the state information for the components that are instantiated from this blueprint. In this case the generated components will have a vault named sample_vault
where they will be able to store tokens on the ledger.impl
section where all of the functions and methods of the instantiated components are defined. Notice that the first function named new
returns a Component
. Because it returns a Component, it acts as a constructor which, when called, instantiates and returns a new component that operates according to this blueprint.new
function first creates a new type of token named "HelloToken" with a fixed supply of 1000. The 1000 created tokens are all stored in a Bucket named my_bucket
. Then it instantiates the component using the syntax shown and, within the body of Self
specifying all of the initial values of the elements listed above in the struct
. In this case, there is only one, sample_vault
, which it creates using the tokens inside my_bucket
.free_token
that returns a Bucket
containing a single token from the sample_vault
. As you can see, the method contains a single parameter &mut self
that is used to get access to the state variables, in this case sample_vault
. Because this is a method (it has a reference to self), you can only call it on instantiated components.resim
to instantiate this blueprint to make a component and then call its method.