Hi guys!
I am currently launching ICRC1 token on ICP using Motoko.
Here’s my code:
type MintArgs = {
to : Principal;
amount : IcpLedger.Tokens;
};
public shared func mint(args: MintArgs) : async Result.Result<IcpLedger.BlockIndex, Text> {
let mintingAccount = await IcpLedger.icrc1_minting_account();
switch (mintingAccount) {
case (null) {
return #err ("Minting account does not exist");
};
case (?mintingAccount) {
let transferArgs : IcpLedger.TransferArg = {
from_subaccount = null;
to = { owner = args.to; subaccount = null };
amount = args.amount;
fee = null;
memo = null;
created_at_time = null;
};
let result = await IcpLedger.icrc1_transfer(transferArgs);
switch (result) {
case (#Ok(blockIndex)) {
return #ok blockIndex;
};
case (#Err(mintError)) {
return #err("Couldn't mint tokens: " # debug_show (mintError));
};
}
};
}
};
I am not sure how this function works.
Should I enter default
’s principal and amount
to mint?
export PRE_MINTED_TOKENS=10_000_000_000
dfx identity use default
export DEFAULT=$(dfx identity get-principal)
export TRANSFER_FEE=10_000
dfx identity new archive_controller
dfx identity use archive_controller
export ARCHIVE_CONTROLLER=$(dfx identity get-principal)
export TRIGGER_THRESHOLD=2000
export CYCLE_FOR_ARCHIVE_CREATION=10000000000000
export NUM_OF_BLOCK_TO_ARCHIVE=1000
export TOKEN_NAME="My Token"
export TOKEN_SYMBOL="XMTK"
dfx identity new minter
dfx identity use minter
export MINTER=$(dfx identity get-principal)
export FEATURE_FLAGS=false
dfx start --clean --background
dfx deploy icrc1_ledger_canister --argument "(variant {Init =
record {
token_symbol = \"${TOKEN_SYMBOL}\";
token_name = \"${TOKEN_NAME}\";
minting_account = record { owner = principal \"${MINTER}\" };
transfer_fee = ${TRANSFER_FEE};
metadata = vec {};
feature_flags = opt record{icrc2 = ${FEATURE_FLAGS}};
initial_balances = vec { record { record { owner = principal \"${DEFAULT}\"; }; ${PRE_MINTED_TOKENS}; }; };
archive_options = record {
num_blocks_to_archive = ${NUM_OF_BLOCK_TO_ARCHIVE};
trigger_threshold = ${TRIGGER_THRESHOLD};
controller_id = principal \"${ARCHIVE_CONTROLLER}\";
cycles_for_archive_creation = opt ${CYCLE_FOR_ARCHIVE_CREATION};
};
}
})"
I deployed my canister like above example.
So you could understand what the default
means.
Thanks
To mint new tokens, you should have the minting account or in this case, the MINTER
principal, call the mint function.
It looks like:
dfx identity use minter
Thanks.
As you can see in the above example, I have minting account.
dfx identity new minter
dfx identity use minter
export MINTER=$(dfx identity get-principal)
But I don’t know what I should put for to
prop in my mint
function.
To -> owner
should the principal that you want to send the new tokens to.
Who would you like to send the new tokens go to?
I don’t want to send tokens to anyone, just to increase amount of total supply
What are your plans for the tokens?
You could send it to default
principal then as it seems like they received the initial batch of tokens. You just want to send it to the minter
because the minter
calling the mint
function would not mint anything in this case.
I just want to increase total supply by calling the mint function.
How can I update my code?
- Get the value for default principal
dfx identity use default
dfx identity get-principal
Save this value for the next section.
- Update to with the principal value above.
type MintArgs = {
to : principal_value;
amount : IcpLedger.Tokens;
};