1

I used a package called @project-serum/sol-wallet-adapter and I want to use createMint() and mintTo() functions in @solana/spl-token. The problem is that I can't get the feePayer or the Signer in order to make createMint() work.

Code (what I need):

const mint = await Token.createMint(
        connection,
        wallet, // I need this signer which i cannot get from @project-serum/sol-wallet-adapter
        wallet.publicKey,
        wallet.publicKey,
        9,
        TOKEN_PROGRAM_ID
      );

// Everything else is good

If anybody can tell me a solution, that would be great!

1
  • No comments on this one ? If any of you have example how to createMint() on solana mainnet that would be great as well!
    – user2447
    Commented Oct 17, 2022 at 20:00

1 Answer 1

2

When using a wallet, you have to use a different flow than the Token class, which is one of the reasons why it was removed. Rather than passing in the Keypair, you'll need to create a transaction and have it signed by the wallet, ie:

const lamports = await getMinimumBalanceForRentExemptMint(connection);

const transaction = new Transaction().add(
    SystemProgram.createAccount({
        fromPubkey: payer.publicKey,
        newAccountPubkey: keypair.publicKey,
        space: MINT_SIZE,
        lamports,
        programId,
    }),
    createInitializeMint2Instruction(keypair.publicKey, decimals, mintAuthority, freezeAuthority, programId)
);
let { blockhash } = await connection.getRecentBlockhash();
transaction.recentBlockhash = blockhash;
transaction.feePayer = wallet.publicKey;
let signed = await wallet.signTransaction(transaction);

This was adapted from https://github.com/solana-labs/solana-program-library/blob/master/token/js/src/actions/createMint.ts

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.