0

I get the error when trying to mint tokens on web3 with mintToChecked function.

Here's the code:

async function mintToken(
    connection: web3.Connection,
    payer: web3.Keypair,
    userAddress: web3.PublicKey
) {
    const tokenMint = await spl.createMint(
        connection,
        payer,
        userAddress,
        userAddress,
        8
    );
    console.log("token mint: ", tokenMint.toBase58());

    const userTokenAddress = await spl.createAssociatedTokenAccount(
        connection,
        payer,
        tokenMint,
        userAddress
    );
    console.log("user token address: ", userTokenAddress.toBase58());

    const tx = await spl.mintToChecked(
        connection,
        payer,
        tokenMint,
        userTokenAddress,
        userAddress,
        100,
        8
    );
    console.log("mint tx: ", tx);

    const userTokenAmount = await connection.getTokenAccountBalance(
        userTokenAddress
    );
    console.log("user token amount: ", userTokenAmount);
}

1 Answer 1

1

The mint transaction isn't being signed by userAddress, since you're passing in a Pubkey instead of a Signer. Assuming you have userSigner, where userAddress = userSigner.publicKey, you should do:

    const tx = await spl.mintToChecked(
        connection,
        payer,
        tokenMint,
        userTokenAddress,
        userSigner,
        100,
        8
    );
2
  • It's working now. Thanks. Don't understand why it also accepts PublicKey, if it needs a signer.
    – denimcodes
    Commented Apr 21, 2023 at 4:47
  • 1
    In the case of a multisig, you pass in the Pubkey of the multisig, then the actual multisig participants sign in the multiSigners parameter, so it doesn't always need a signer. Agreed that it's unclear, especially since multisigs aren't very common
    – Jon C
    Commented Apr 21, 2023 at 17:01

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.