Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions clients/js/src/createMint.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { getCreateAccountInstruction } from '@solana-program/system';
import { Address, InstructionPlan, OptionOrNullable, sequentialInstructionPlan, TransactionSigner } from '@solana/kit';
import {
Address,
getMinimumBalanceForRentExemption,
InstructionPlan,
OptionOrNullable,
sequentialInstructionPlan,
TransactionSigner,
} from '@solana/kit';
import { getInitializeMint2Instruction, getMintSize, TOKEN_PROGRAM_ADDRESS } from './generated';

// RPC `getMinimumBalanceForRentExemption` for 82 bytes, which is token mint size
// Hardcoded to avoid requiring an RPC request each time
const MINIMUM_BALANCE_FOR_MINT = 1461600;

export type CreateMintInstructionPlanInput = {
/** Funding account (must be a system account). */
payer: TransactionSigner;
Expand All @@ -19,7 +22,7 @@ export type CreateMintInstructionPlanInput = {
freezeAuthority?: OptionOrNullable<Address>;
/**
* Optional override for the amount of Lamports to fund the mint account with.
* @default 1461600
* @default enough to make the account rent-exempt (currently 1,461,600 Lamports)
* */
mintAccountLamports?: number;
};
Expand All @@ -38,7 +41,7 @@ export function getCreateMintInstructionPlan(
{
payer: input.payer,
newAccount: input.newMint,
lamports: input.mintAccountLamports ?? MINIMUM_BALANCE_FOR_MINT,
lamports: input.mintAccountLamports ?? getMinimumBalanceForRentExemption(BigInt(getMintSize())),
space: getMintSize(),
programAddress: config?.tokenProgram ?? TOKEN_PROGRAM_ADDRESS,
},
Expand Down