Functions and Methods

Functions and methods form the primary part of the implementation of a blueprint; they define the behavior to accomplish specific tasks. Calls to functions and methods are also how transactions interact with blueprints and components on the Radix network.

Functions

Functions are similar to what you think of as a "static function" in other languages. They do not depend on any internal state, and can be called directly on a blueprint. Typically, a blueprint offers at least one function that performs instantiation of a component.

Functions can have input parameters and return values, they just can’t have a reference to self.

Here’s an example of a function signature that instantiates a component:

pub fn instantiate_my_component(init_count: u32) -> Component {

Methods

Methods require a reference to self, and can read and modify internal state. Methods can only be called on components (blueprints don’t have internal state).

The first argument of a method is either &self or &mut self:

  • With &self, the statements within the method can only read the component state

  • With &mut self, the statements can read and write the component state

Some example method signatures:

pub fn get_value(&self) -> u32 {
pub fn update_value(&mut self, new_value: u32) {

Visibility

All public functions and methods defined in a blueprint may be invoked by external entities via transactions or calls from other functions or methods. Methods are only invokable on an instantiated component.

To check what functions and methods are available on a blueprint deployed to your local simulator, run this command:

resim export-abi <PACKAGE_ADDRESS> <BLUEPRINT_NAME>