Entry Functions
The entry modifier for functions enables safe and direct invocation of module functions, much like scripts. Providing an entry function defines where your module's execution should begin. You can assume that any non-entry function is being called from a Move program already in execution.
You can combine the entry modifier with other visibility modifiers, such as public (which allows calling from other modules) and public(friend) for calling from friend modules.
Essentially, entry functions are the "main" functions of a module, and they specify where Move programs start executing.
module examples::object {
use sui::transfer;
use sui::object::{Self, UID};
use sui::tx_context::TxContext;
struct Object has key {
id: UID
}
/// If function is defined as public - any module can call it.
/// Non-entry functions are also allowed to have return values.
public fun create(ctx: &mut TxContext): Object {
Object { id: object::new(ctx) }
}
/// Entrypoints can't have return values as they can only be called
/// directly in a transaction and the returned value can't be used.
/// However, `entry` without `public` disallows calling this method from
/// other Move modules.
entry fun create_and_transfer(to: address, ctx: &mut TxContext) {
transfer::transfer(create(ctx), to)
}
}