gill

buildMintTokensTransaction

Call Signature

function buildMintTokensTransaction<TVersion, TFeePayer>(args): Promise<{
  feePayer: Readonly<{
     address: Address<TAddress>;
  }>;
  instructions: readonly IInstruction<string, readonly (IAccountLookupMeta<string, string> | IAccountMeta<string>)[]>[];
  version: TVersion;
}>;

Create a transaction that can mint tokens to the desired wallet/owner, including creating their ATA if it does not exist

The transaction has the following defaults:

  • Default version = legacy
  • Default computeUnitLimit = 31_000

Example

const destination = address("nicktrLHhYzLmoVbuZQzHUTicd2sfP571orwo9jfc8c");

const mint = address(...);
// or mint can be a keypair from a freshly created token

const transaction = await buildMintTokensTransaction({
  feePayer: signer,
  latestBlockhash,
  mint,
  mintAuthority: signer,
  amount: 1000, // note: be sure to consider the mint's `decimals` value
  // if decimals=2 => this will mint 10.00 tokens
  // if decimals=4 => this will mint 0.100 tokens
  destination,
  // tokenProgram: TOKEN_PROGRAM_ADDRESS, // default
  // tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,
});

Type Parameters

Type ParameterDefault type
TVersion extends TransactionVersion"legacy"
TFeePayer extends TransactionSignerTransactionSigner

Parameters

ParameterType
args{ computeUnitLimit?: number | bigint; computeUnitPrice?: number | bigint; latestBlockhash?: undefined; version?: TVersion; } & { amount: number | bigint; ata?: Address; destination: Address | TransactionSigner; feePayer: Address | TransactionSigner; mint: Address | KeyPairSigner; mintAuthority: Address | TransactionSigner; tokenProgram?: Address; }

Returns

Promise<{ feePayer: Readonly<{ address: Address<TAddress>; }>; instructions: readonly IInstruction<string, readonly (IAccountLookupMeta<string, string> | IAccountMeta<string>)[]>[]; version: TVersion; }>

Remarks

  • minting without creating the ata is generally < 10_000cu
  • validating the ata onchain during creation results in a ~5000cu fluctuation

Call Signature

function buildMintTokensTransaction<TVersion, TFeePayer, TLifetimeConstraint>(args): Promise<{
  feePayer: Readonly<{
     address: Address<TAddress>;
  }>;
  instructions: readonly IInstruction<string, readonly (IAccountLookupMeta<string, string> | IAccountMeta<string>)[]>[];
  lifetimeConstraint: BlockhashLifetimeConstraint;
  version: TVersion;
}>;

Create a transaction that can mint tokens to the desired wallet/owner, including creating their ATA if it does not exist

The transaction has the following defaults:

  • Default version = legacy
  • Default computeUnitLimit = 31_000

Example

const destination = address("nicktrLHhYzLmoVbuZQzHUTicd2sfP571orwo9jfc8c");

const mint = address(...);
// or mint can be a keypair from a freshly created token

const transaction = await buildMintTokensTransaction({
  feePayer: signer,
  latestBlockhash,
  mint,
  mintAuthority: signer,
  amount: 1000, // note: be sure to consider the mint's `decimals` value
  // if decimals=2 => this will mint 10.00 tokens
  // if decimals=4 => this will mint 0.100 tokens
  destination,
  // tokenProgram: TOKEN_PROGRAM_ADDRESS, // default
  // tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,
});

Type Parameters

Type ParameterDefault type
TVersion extends TransactionVersion"legacy"
TFeePayer extends TransactionSignerTransactionSigner
TLifetimeConstraint extends Readonly<{ blockhash: Blockhash; lastValidBlockHeight: bigint; }>Readonly<{ blockhash: Blockhash; lastValidBlockHeight: bigint; }>

Parameters

ParameterType
args{ computeUnitLimit?: number | bigint; computeUnitPrice?: number | bigint; latestBlockhash?: TLifetimeConstraint; version?: TVersion; } & { amount: number | bigint; ata?: Address; destination: Address | TransactionSigner; feePayer: Address | TransactionSigner; mint: Address | KeyPairSigner; mintAuthority: Address | TransactionSigner; tokenProgram?: Address; }

Returns

Promise<{ feePayer: Readonly<{ address: Address<TAddress>; }>; instructions: readonly IInstruction<string, readonly (IAccountLookupMeta<string, string> | IAccountMeta<string>)[]>[]; lifetimeConstraint: BlockhashLifetimeConstraint; version: TVersion; }>

Remarks

  • minting without creating the ata is generally < 10_000cu
  • validating the ata onchain during creation results in a ~5000cu fluctuation

On this page