# How to create a function for minting tokens?

**URL:** https://forum.dfinity.org/t/how-to-create-a-function-for-minting-tokens/34137
**Category:** Motoko
**Created:** [August 14, 2024, 1:31am UTC](https://forum.dfinity.org/t/how-to-create-a-function-for-minting-tokens/34137 "2024-08-14T01:31:32Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![jennifertran](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jennifertran/32/11558_2.png) [@jennifertran](https://forum.dfinity.org/u/jennifertran)
#### Post date: [August 14, 2024, 5:00pm UTC](https://forum.dfinity.org/t/how-to-create-a-function-for-minting-tokens/34137/2 "2024-08-14T17:00:52Z")

</div>

Hello there, are you using ICRC1/ICRC2?

Any transfers from the `minter account` you specified would mint new tokens upon creating the token.

The `minter account` would need to call the function.

There is a minting function example from the [Token transfer] example ([Token transfer | Internet Computer](https://internetcomputer.org/docs/current/references/samples/motoko/token_transfer/)).

```auto
public shared ({ caller }) func transfer(args : TransferArgs) : async Result.Result<Icrc1Ledger.BlockIndex, Text> {
    Debug.print(
      "Transferring "
      # debug_show (args.amount)
      # " tokens to account"
      # debug_show (args.toAccount)
    );

    let transferArgs : Icrc1Ledger.TransferArg = {
      // can be used to distinguish between transactions
      memo = null;
      // the amount we want to transfer
      amount = args.amount;
      // we want to transfer tokens from the default subaccount of the canister
      from_subaccount : args.minterSubaccount; };
      // if not specified, the default fee for the canister is used
      fee = null;
      // we take the principal and subaccount from the arguments and convert them into an account identifier
      to = args.toAccount;
      // a timestamp indicating when the transaction was created by the caller; if it is not specified by the caller then this is set to the current ICP time
      created_at_time = null;
    };

    try {
      // initiate the transfer
      let transferResult = await Icrc1Ledger.icrc1_transfer(transferArgs);

      // check if the transfer was successfull
      switch (transferResult) {
        case (#Err(transferError)) {
          return #err("Couldn't transfer funds:\n" # debug_show (transferError));
        };
        case (#Ok(blockIndex)) { return #ok blockIndex };
      };
    } catch (error : Error) {
      // catch any errors that might occur during the transfer
      return #err("Reject message: " # Error.message(error));
    };
  };
};

```

You can refer to this [forum post](https://forum.dfinity.org/t/how-to-mint-icrc2-tokens/29631).

---

_[View the full topic](https://forum.dfinity.org/t/how-to-create-a-function-for-minting-tokens/34137)._
