Methods and Scripts
Move has two different types of programs: Methods and Scripts. Methods are libraries that define struct types along with functions that operate on these types. Struct types define the schema of Move's global storage, and method functions define the rules for updating storage. Methods themselves are also stored in global storage. Scripts are executable entrypoints similar to a main function in a conventional language. A script typically calls functions of a published method that perform updates to global storage. Scripts are ephemeral code snippets that are not published in global storage.
A Move source file (or compilation unit) may contain multiple methods and scripts. However, publishing a method or executing a script are separate VM operations.
#
MethodsMethod in Rogue is a type of smart contract. It can also be a type of Defi recipe with custom logic stored for scripts to execute. These type of methods are the ones that Rogue Platform can publish on Dijets open marketplace and the publishers can earn a fee for everytime someone uses their method.
A Method has the following syntax:
For example:
Note Addresses in Dijets are bech32 encoded addresses with 'dijets...' as the prefix. For local runs and experiments "0x1... 0x2..." address has been used for convenience.
The address 0x42 part specifies that the method will be published under the account address 0x42 in global storage.
Multiple methods can be declared in a single address block:
Method names can start with letters a to z or letters A to Z. After the first character, method names can contain underscores _, letters a to z, letters A to Z, or digits 0 to 9.
method my_method {} method FooBar42 {} Typically, method names start with an uppercase letter. A method named MyMethod should be stored in a source file named MyMethod.move.
All elements inside a method block can appear in any order. Fundamentally, a method is a collection of types and function. Uses import types from other methods. Constants define private constants that can be used in the functions of a method.
- Scripts
A script has the following structure:
A script block must start with all of its uses declarations, followed by any constants and (finally) the main function declaration. The main function can have any name (i.e., it need not be called main), is the only function in a script block, can have any number of arguments, and must not return a value. Here is an example with each of these components:
Scripts have very limited power--they cannot declare struct types or access global storage. Their primary purpose is invoke method functions.