How to call move function with option argument in typescript sdk

This is the move function:

    public fun self_remove_locker(
        locker_cap: &mut LockerCap,
        telebtc_cap: &mut TeleBTCCap,
        treasury_cap: &mut TreasuryCap<TELEBTC>,
        telebtc_coins: &mut Option<Coin<TELEBTC>>,
        ctx: &mut TxContext
    ): bool {
       // fun code
    }

So I have tried lots of methods and none of them work.

const tx = new TransactionBlock();
tx.setGasBudget(500000000);
tx.moveCall({
target: `${lockerPackageId}::lockermanager::self_remove_locker`,
arguments: [
     tx.object(lockerCapId),
     tx.object(telebtcCapId),
     tx.object(telebtcTreasuryCapId),
     //tx.pure(null, `0x1::option::Option<0x2::coin::Coin<${lockerPackageId}::telebtc::TELEBTC>>`)

                ]
            });

AI agent provides lots of examples and none of them work. If pass null or None, the sdk will fail. If pass nothing, I will get incorrect function arguments. This drives my crazy!

Does anyone have similar project code or know how to solve this issue?

Have you tried passing noneCoin produced like this,

const T_COIN = 0x2::coin::Coin<${lockerPackageId}::telebtc::TELEBTC>;
const tx = new TransactionBlock();
tx.setGasBudget(500_000_000);
const noneCoin = tx.moveCall({
target: ‘0x1::option::none’,
typeArguments: [T_COIN],
arguments: ,
});

1 Like

Dude, you are a genius, it works!!

Full code for future people who needed:

// Create a none option for the telebtc_coins parameter

        const T_COIN = \`0x2::coin::Coin<${lockerPackageId}::telebtc::TELEBTC>\`;

        const noneCoin = tx.moveCall({

            target: '0x1::option::none',

            typeArguments: \[T_COIN\],

            arguments: \[\]

        });

        

        tx.moveCall({

            target: \`${lockerPackageId}::lockermanager::self_remove_locker\`,

            arguments: \[

                tx.object(lockerCapId),

                tx.object(telebtcCapId),

                tx.object(telebtcTreasuryCapId),

                tx.object(noneCoin),

            \]

        });
1 Like