Skip to main content

Aptos Coin Deployment

May 23, 2023
Yoonsoo Jang
Software Engineer, DSRV

Introduction

This tutorial shows how to deploy your own coin.

info

Please refer to here to get started.

Create Template

Create a simple example contract code written in Move. You can create a sample contract moon_coin by selecting the template option and clicking the Create Template button.

template-code-aptos-moon-coin

Source Code

Note that init_module function is executed only once during deployment.

moon_coin.move
module MoonCoin::moon_coin {
use aptos_framework::coin;

struct MoonCoin {}

fun init_module(sender: &signer) {
aptos_framework::managed_coin::initialize<MoonCoin>(
sender,
b"Moon Coin",
b"MOON",
6,
false,
);
}

public entry fun register(account: &signer) {
aptos_framework::managed_coin::register<MoonCoin>(account)
}

public entry fun mint(account: &signer, dst_addr: address, amount: u64) {
aptos_framework::managed_coin::mint<MoonCoin>(account, dst_addr, amount);
}

public entry fun burn(account: &signer, amount: u64) {
aptos_framework::managed_coin::burn<MoonCoin>(account, amount);
}

public entry fun transfer(from: &signer, to: address, amount: u64,) {
coin::transfer<MoonCoin>(from, to, amount);
}
}

Note that you should replace MoonCoin address _ of your own account address.

Move.toml
[package]
name = "Examples"
version = "0.0.0"

[addresses]
MoonCoin = "_"

[dependencies]
AptosFramework = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/aptos-framework/", rev = "main" }

Compile The Source Code

Select the project you want to compile. For now, let's choose aptos/moon_coin and click Compile button.

project-to-compile-moon-coin

Deployment

If the compilation succeed, you can see mv file moon-coin.mv.

Click the Deploy button.

build-file-moon-coin

and you can see wallet popup. Let's click Send button.

aptos-moon-coin-wallet-popup

Check Out Deployed Contract

After deployment, you can see moon_coin module and functions.

aptos-moon-coin-deployed

Calling Contract Functions

  1. Call register function to accept deposits of MoonCoin.

    aptos-moon-coin-register
  2. Select mint function. First parameter is the address of receiver for minting coin and second parameter is the amount of minting coin. For now, set your account address for the first parameter because you have already registered above. The receiver should call register before calling mint.

    aptos-moon-coin-mint
  3. Check if the coin have been minted in Aptos Explorer Coins tab.

    aptos-moon-coin-minted

Try more...

  1. Call burn function and check it out in Aptos Explorer Coins tab.
  2. Create and switch to new account address and try register. Switch to the original address again and transfer or mint to the address you just newly created.

Reference

https://aptos.dev/tutorials/your-first-coin/