klren0312 / daliy_knowledge

知识积累,正确使用方式是watch
21 stars 4 forks source link

sui 创建自己的coin并mint #860

Open klren0312 opened 2 weeks ago

klren0312 commented 2 weeks ago

合约

暴露两个方法 burnmint,这两个方法只能合约发起者进行执行

module move_coin::ZCDCCOIN {
    use sui::coin::{Self, Coin, TreasuryCap};
    use sui::url;
    public struct ZCDCCOIN has drop {}

    /// Module initializer is called once on module publish. A treasury
    /// cap is sent to the publisher, who then controls minting and burning
    fun init(witness: ZCDCCOIN, ctx: &mut TxContext) {
        let (treasury, metadata) = coin::create_currency(
          witness,
          6,
          b"ZCDCCoin",
          b"ZCDCCoin",
          b"ZCDCCoin is NO.1",
        option::some(url::new_unsafe_from_bytes(b"https://aggregator.walrus-testnet.walrus.space/v1/n-e_Ni4LwoBJUwu_Ovccl7Lflh_NmHmvwMpLWLRwCt0")),
          ctx
        );
        transfer::public_freeze_object(metadata);
        transfer::public_transfer(treasury, tx_context::sender(ctx));
    }

    public entry fun mint (
        treasury_cap: &mut TreasuryCap<ZCDCCOIN>, amount: u64, recipient: address, ctx: &mut TxContext
    ) {
        coin::mint_and_transfer(treasury_cap, amount, recipient, ctx)
    }

    public entry fun burn (
        treasury_cap: &mut TreasuryCap<ZCDCCOIN>, coin: Coin<ZCDCCOIN>
    ) {
        coin::burn(treasury_cap, coin);
    }
}

打包发布合约

sui move build
sui client publish

记录下TreasuryCap的objectid 用于mint币 image

mint币

https://suiscan.xyz/testnet/object/0x14789a6e47d1c1a11890e9315daa666079745b9df3f3618ab9f6ec820da9f9d3/contracts

第一个参数写刚刚记录的objectid,第二个写币的数量,第三个写你的钱包地址 image

查看币

image