1

I want to use the createMint function in '@solana/spl-token'.

I don't want to use Keypair.generate() when I call a function.

Here is my code:

export const createToken = async () => {
  const wallet = Keypair.generate();
  const connection = new Connection(clusterApiUrl("devnet"), "confirmed");
  await connection.requestAirdrop(wallet.publicKey, LAMPORTS_PER_SOL);
  const mint = await createMint(
    connection,
    wallet._keypair,
    wallet.publicKey,
    null,
    9,
    TOKEN_PROGRAM_ID,
  );

  console.log(mint.toBase58());
};

This code returns undefined 'toString'. I don't know why it returns undefined.

I've already tried 'wallet._keypair' and 'wallet'.

0

1 Answer 1

1

Your call to createMint is missing a few parameters.

The signature for createMint is:

export async function createMint(
    connection: Connection,
    payer: Signer,
    mintAuthority: PublicKey,
    freezeAuthority: PublicKey | null,
    decimals: number,
    keypair = Keypair.generate(),
    confirmOptions?: ConfirmOptions,
    programId = TOKEN_PROGRAM_ID
): Promise<PublicKey>

I dont want to use Keypair.generate() when I call a function.

You can pass in undefined, so the default value will be used.

Your call should look like this:

  const mint = await createMint(
    connection,
    wallet,
    wallet.publicKey,
    null,
    9,
    undefined,
    {},
    TOKEN_PROGRAM_ID, // optional, can be omitted
  );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.