move-langsui

Failing to make a Launchpad module


I'm trying to make a Launchpad (at least the first part) I need that any user calling the function create_coin creates a Coin (for now with its hardcoded data) and gives to him the ownership of the new coin.

I'm failing in something in my code, it's probably a conceptual error on my part.

module launchpad::coin_factory_better {
        use sui::coin::{Self, TreasuryCap};

        public struct COIN has drop {}

        public fun create_coin(ctx: &mut TxContext) {
            let (treasury, metadata) = coin::create_currency(COIN {}, 6, b"ROTT", b"", b"", option::none(), ctx);
            transfer::public_freeze_object(metadata);
            transfer::public_transfer(treasury, ctx.sender());
        }

        ......

}

In the public transfer of the treasury line I receive the following warning:

Transfer of an object to transaction sender address
launchpad.move(11, 14): Returning an object from a function, allows a caller to use the object and enables composability via programmable transactions.
launchpad.move(14, 40): Transaction sender address coming from here
public fun sui::transfer::public_transfer<T>(obj: T, recipient: address)
Transfer ownership of obj to recipient. obj must have the key attribute, which (in turn) ensures that obj has a globally unique ID. Note that if the recipient address represents an object ID, the obj sent will be inaccessible after the transfer (though they will be retrievable at a future date once new features are added). The object must have store to be transferred outside of its module.

But I don't understand, the type TreasuryCap does have id/key by default, so I don't understand where the error is since I consider that treasury has id/key when it is created. I imagine that the error may be in the line: public struct COIN has drop {}

But I still can't find my error, thanks


Solution

  • Apparently, it's not possible to do such a function in Move since it requires the witness (user who executes the transaction). So (I repeat, apparently) the only way is to have the user deploy a Coin bytecode in the frontend.