What is the difference between transfer::transfer and returning something from the method

For a lesson I am following to learn Move/SUI I have this method I need to implement

    /* 
        Withdraws the sales balance from the MinterCap object. This can only be called by the owner 
        of the MinterCap object.
        @param minter_cap - the minter cap object
        @param ctx - the transaction context
        @return the withdrawn coin
    */
    public fun withdraw(
        minter_cap: &mut MinterCap,
        ctx: &mut TxContext,
    ): Coin<SUI> {
        // implement
    }

Up until now, I have always used transfer::transfer(obj, address) to transfer an object to an address, but in this case, this method actually returns Coin<SUI>, so I am not sure how to handle this. Should I use transfer::transfer(coin, address) like I am used to before? or the fact that this method returns Coin<SUI> has a special meaning?

1 Like

You can specify address in transfer::transfer()

true. But I think my main question I have is difference between transfer::transfer(coin, address) and having a sui method that has a return type.

We generally try to “return” from the functions instead of doing self-transfers to allow PTB friendliness and more composable flows.
You can return an object and do something else with it (E.g. call another function that splits it and transfers into two addresses half/half).
With self-transfers, this is not possible in the same PTB.