Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sui 创建自己的coin并mint #860

Open
klren0312 opened this issue Nov 6, 2024 · 0 comments
Open

sui 创建自己的coin并mint #860

klren0312 opened this issue Nov 6, 2024 · 0 comments
Labels
Blockchain 区块链相关问题

Comments

@klren0312
Copy link
Owner

klren0312 commented Nov 6, 2024

合约

暴露两个方法 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

@klren0312 klren0312 added the Blockchain 区块链相关问题 label Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blockchain 区块链相关问题
Projects
None yet
Development

No branches or pull requests

1 participant