initializeMint static method

TransactionInstruction initializeMint({
  1. required Pubkey mint,
  2. required u8 decimals,
  3. required Pubkey mintAuthority,
  4. Pubkey? freezeAuthority,
})

Initializes a new mint and optionally deposits all the newly minted tokens in an account.

The initializeMint instruction requires no signers and MUST be included within the same Transaction as the system program's createAccount instruction that creates the account being initialized. Otherwise another party can acquire ownership of the uninitialized account.

Keys:

  • [w] mint - The mint to initialize.

Data:

  • decimals - Number of base 10 digits to the right of the decimal place.
  • mintAuthority - The authority/multisignature to mint tokens.
  • freezeAuthority - The freeze authority/multisignature of the mint.

Implementation

static TransactionInstruction initializeMint({
  // Keys
  required final Pubkey mint,
  // Data
  required final u8 decimals,
  required final Pubkey mintAuthority,
  final Pubkey? freezeAuthority,
}) {
  // 0. `[w]` The mint to initialize.
  // 1. `[]` Rent sysvar.
  final List<AccountMeta> keys = [
    AccountMeta.writable(mint),
    AccountMeta(sysvarRentPubkey),
  ];

  final List<Iterable<int>> data = [
    borsh.u8.encode(decimals),
    borsh.pubkey.encode(mintAuthority.toBase58()),
    borsh.pubkey.cOption().encode(freezeAuthority?.toBase58()),
  ];

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