How to pass an Option<T> to a function?

,

Hi,

So I created a function and it has an optional parameter with the type of sui::object::ID.

public entry fun equip_gear<T: drop + store>(
        dog: Nft<DOG>,
        equipment_old: Option<ID>,
        equipment_new: Nft<DOG>,
        collection: &Collection<DOG>,
        ctx: &mut TxContext,
    ){
        let sender = tx_context::sender(ctx);

        if(option::is_some(&equipment_old)){
            let equipment_old_ex = option::extract(&mut equipment_old);
            c_nft::decompose_and_transfer<DOG, Dog, T>(
                &mut dog, equipment_old_ex, ctx
            );
        };

        c_nft::compose<DOG, Dog, T>(
            &mut dog, equipment_new, collection
        );

        transfer::public_transfer(dog, sender);
    }

However when I go to the explorer and fill in the info I need to fill something in on the Option parameter. See image.

If I use the SUI CLI I also need to fill in something:

sui client call --package ${package_id} --module dog --type-args ${package_id}::dog::Background --function equip_gear --args 0x14655a94b5d4a3bb8da2c621c3106437bea9f426cb346055f2bf6243031bea8b ${option_parameter} 0x2d3c2ce1aef2e7046dd49893e3995edd986df6585b89c756beef1d5a20fa246c 0xbb30da6bfc043314813a9a30787858d7d71b9c0a984d7a9003ca2d9449e47630 --gas-budget 30000

What needs to be filled in inside the ${option_parameter}, if its supposed to be empty?

7 Likes

Can’t immediately check, but I remember RPC API description mentioned we use empty array to represent empty option. So perhaps try '[ ]' or something like this

7 Likes