Rise In Logo





Move on Sui Course

Functions

Functions in Sui are blocks of code that can perform a specific task. They can be defined inside modules or outside of them

  • The function can be public, public (friend), or internal.
  • Public functions can be called by anyone, public (friend) functions can be called by the module itself or its friends, and internal functions can only be called by the module itself.
  • Functions can have parameters and return values, and they can use local variables and expressions.
  • Functions can also call other functions or use the Sui Framework libraries. Here is an example of a function in Sui:
// This is a public function that takes two u64 values as parameters and returns their sum
public fun add(x: u64, y: u64): u64 {
    x + y // This is an expression that returns the sum of x and y
}
Rise In Logo

Rise together in web3