# Sui Move Lecture #4 Functions and strings

By [Artech.Club](https://paragraph.com/@artechclub) · 2023-05-18

---

In this lecture, we will talk about `functions` and `strings` in Sui Move.

You can see the public functions of any packages with explorer.

![public functions](https://storage.googleapis.com/papyrus_images/0dbcfebfe78ec361551fb42a9f2e936f223db26b4acb0af0fbecd6e743f0b0b5.png)

public functions

Function Visibility
-------------------

Sui Move functions have three types of visibility:

*   **private**: the default visibility of a function; it can only be accessed by functions inside the same module
    
*   **public**: the function is accessible by functions inside the same module, and by functions defined in another module
    
*   **public(friend)**: the function is accessible by functions inside the same module and by functions defined in modules that are included on the module's [friends list.](https://diem.github.io/move/friends.html)
    
    ### Return Value
    
    The return type of a function is specified in the function signature after the function parameters, separated by a colon.
    

A function's last line (of execution) without a semicolon is the return value.

Example:

    public fun addition (a: u8, b: u8): u8 {
        a + b    
    }
    

### Entry Functions

In Sui Move, entry functions are simply functions that can be called by a transactions. They must satisfy the following three requirements:

*   Denoted by the keyword `entry`
    
*   have no return value
    
*   (optional) have a mutable reference to an instance of the `TxContext` type in the last parameter
    
    example:
    
    [https://github.com/seapad-fund/sui-contracts/blob/master/nft/sources/nftbox\_entries.move](https://github.com/seapad-fund/sui-contracts/blob/master/nft/sources/nftbox_entries.move)
    
    ### Transaction Context
    
    Entry functions typically have an instance of `TxContext` as the last parameter. This is a special parameter set by the Sui Move VM, and does not need to be specified by the user calling the function.
    

The `TxContext` object contains [essential information](https://github.com/MystenLabs/sui/blob/main/crates/sui-framework/packages/sui-framework/sources/tx_context.move) about the transaction used to call the entry function, such as:

*   the sender's address
    
*   the signer's address
    
*   the tx's epoch, etc.
    

### Create the mint Function

We can define our minting function in the Hello World example as the following:

    public entry fun mint(ctx: &mut TxContext) {
        let object = HelloWorldObject {
            id: object::new(ctx),
            text: string::utf8(b"Hello World!")
        };
        transfer::transfer(object, tx_context::sender(ctx));
    }
    

This function simply creates a new instance of the `HelloWorldObject` custom type, then uses the Sui system transfer function to send it to the transaction caller.

Example:

[https://github.com/seapad-fund/sui-contracts/blob/1d062984acdc53916001bcedc7b103f577a6112b/nft/sources/nftbox.move#L405](https://github.com/seapad-fund/sui-contracts/blob/1d062984acdc53916001bcedc7b103f577a6112b/nft/sources/nftbox.move#L405)

String
------

Move does not have primitive string type, but it has a package to handle it.

    module examples::strings {
        use sui::object::{Self, UID};
        use sui::tx_context::TxContext;
    
        // import dependency
        use std::string::{Self, String};
    
        // an Object with a string
        struct Name has key, store {
            id: UID,
    
            /// Here it is - the String type
            name: String
        }
    
        // create a new Name Object with raw bytes
        public fun issue_name_nft(
            name_bytes: vector<u8>, ctx: &mut TxContext
        ): Name {
            Name {
                id: object::new(ctx),
                name: string::utf8(name_bytes)
            }
        }
    }
    

The `hello world` example used string as well.

        public entry fun mint(ctx: &mut TxContext) {
            let object = HelloWorldObject {
                id: object::new(ctx),
    
            // Here
                text: string::utf8(b"Hello World!")
            };
            transfer::transfer(object, tx_context::sender(ctx));
        }
    

**Reference**

[https://github.com/sui-foundation/sui-move-intro-course/blob/main/unit-one/lessons/3\_custom\_types\_and\_abilities.md](https://github.com/sui-foundation/sui-move-intro-course/blob/main/unit-one/lessons/3_custom_types_and_abilities.md)

---

*Originally published on [Artech.Club](https://paragraph.com/@artechclub/sui-move-lecture-4-functions-and-strings)*
