Init, Publisher & Display

| | Sui | Aptos | |-|-----|-------| | Name | fun init(ctx: &mut TxContext) or fun init(otw: OTW, ctx: &mut TxContext) | fun init_module(deployer: &signer) | | Runs | Once at publish, per module | Once at first publish, per module | | On upgrade | Not re-run…

32.1 Module initializers

| | Sui | Aptos | |-|-----|-------| | Name | fun init(ctx: &mut TxContext) or fun init(otw: OTW, ctx: &mut TxContext) | fun init_module(deployer: &signer) | | Runs | Once at publish, per module | Once at first publish, per module | | On upgrade | Not re-run — provide an explicit admin-gated migration function instead | Runs for newly added modules only | | Visibility | Must be private | Must be private |

32.2 Publisher (Sui)

A Publisher object proves authority over a package's types. It is claimed with the OTW:

A Publisher can check publisher.from_module<T>() / from_package<T>() and is required to create Display<T> and TransferPolicy<T>.

module nft::art;

use sui::package;

public struct ART has drop {}

fun init(otw: ART, ctx: &mut TxContext) {
    package::claim_and_keep(otw, ctx);   // transfers Publisher to the sender
    // or: let publisher = package::claim(otw, ctx);
}

32.3 Display (Sui object display standard)

Display<T> tells wallets and explorers how to render objects of type T using templates:

Standard keys: name, description, image_url, link, project_url, creator, thumbnail_url. {field} placeholders are filled from object fields.

On Aptos, metadata lives directly in the Digital Asset standard (collection/token URIs, names, descriptions) and fungible asset metadata objects.

module nft::art;

use std::string::{String, utf8};
use sui::package;
use sui::display;

public struct ART has drop {}

public struct Artwork has key, store {
    id: UID,
    name: String,
    image_url: String,
    artist: address,
}

fun init(otw: ART, ctx: &mut TxContext) {
    let publisher = package::claim(otw, ctx);

    let keys = vector[
        utf8(b"name"),
        utf8(b"image_url"),
        utf8(b"description"),
        utf8(b"creator"),
    ];
    let values = vector[
        utf8(b"{name}"),
        utf8(b"{image_url}"),
        utf8(b"An artwork by {artist}"),
        utf8(b"Move Course Studio"),
    ];

    let mut disp = display::new_with_fields<Artwork>(&publisher, keys, values, ctx);
    disp.update_version();   // emits event so indexers pick up the template

    transfer::public_transfer(publisher, ctx.sender());
    transfer::public_transfer(disp, ctx.sender());
}