mintToChecked static method

TransactionInstruction mintToChecked({
  1. required Pubkey mint,
  2. required Pubkey account,
  3. required Pubkey mintAuthority,
  4. List<Pubkey> signers = const [],
  5. required bu64 amount,
  6. required u8 decimals,
})

Mints new tokens to an account. The native mint does not support minting.

This instruction differs from MintTo in that the decimals value is checked by the caller. This may be useful when creating transactions offline or within a hardware wallet.

Keys:

Single authority

  • [w] mint - The mint.
  • [w] account - The account to mint tokens to.
  • [s] mintAuthority - The mint's minting authority.

Multisignature authority

  • [w] mint - The mint.
  • [w] account - The account to mint tokens to.
  • [] mintAuthority - The mint's multisignature mint-tokens authority.
  • [s] signers - The signer accounts.

Data:

  • amount - The amount of new tokens to mint.
  • decimals - Expected number of base 10 digits to the right of the decimal place.

Implementation

static TransactionInstruction mintToChecked({
  // Keys
  required final Pubkey mint,
  required final Pubkey account,
  required final Pubkey mintAuthority,
  final List<Pubkey> signers = const [],
  // Data
  required final bu64 amount,
  required final u8 decimals,
}) {
  // * Single authority
  // 0. `[writable]` The mint.
  // 1. `[writable]` The account to mint tokens to.
  // 2. `[signer]` The mint's minting authority.
  //
  // * Multisignature authority
  // 0. `[writable]` The mint.
  // 1. `[writable]` The account to mint tokens to.
  // 2. `[]` The mint's multisignature mint-tokens authority.
  // 3. ..3+M `[signer]` M signer accounts.
  final List<AccountMeta> keys = [
    AccountMeta.writable(mint),
    AccountMeta.writable(account),
    AccountMeta(mintAuthority, isSigner: signers.isEmpty),
    for (final Pubkey signer in signers) AccountMeta.signer(signer),
  ];

  final List<Iterable<u8>> data = [
    borsh.u64.encode(amount),
    borsh.u8.encode(decimals),
  ];

  return _instance.createTransactionIntruction(
    TokenInstruction.mintToChecked,
    keys: keys,
    data: data,
  );
}