0

I've got a Next.js application making a few transactions calls using '@solana/wallet-adapter-react' and @solana/spl-token

The application has been working fine locally until with the transactions working as expected and creating new tokens, (I have other calls not included for revoking authority etc that were working as well)

With zero changes made to the code I'm now encountering all these tx's failing. The transaction in Phantom that usually shows +X tokens and - X sol to create a token now shows No assets changing and the instructions seem like they're missing data.

Below is the createToken call and an example of what Phantom looks like for a tx that won't be sent.

                SystemProgram.transfer({
                    fromPubkey: publicKey,
                    toPubkey: creationFeeRecipientPublicKey, // account 1
                    lamports: LAMPORTS_PER_SOL * 0.069,
                }),
                SystemProgram.createAccount({
                    fromPubkey: publicKey,
                    newAccountPubkey: mintKeypair.publicKey,
                    space: MINT_SIZE,
                    lamports: lamports,
                    programId: TOKEN_PROGRAM_ID,
                }),
                createInitializeMintInstruction(
                    mintKeypair.publicKey,
                    Number('9'),
                    publicKey,
                    publicKey,
                    TOKEN_PROGRAM_ID
                ),
                createAssociatedTokenAccountInstruction(publicKey, tokenATA, publicKey, mintKeypair.publicKey),
                createMintToInstruction(
                    mintKeypair.publicKey,
                    tokenATA,
                    publicKey,
                    Number(supply) * Math.pow(10, Number('9'))
                ),
                createMetadataInstruction
            );

phantom tx details

phantom tx

3
  • 1
    Did you make sure you have enough sol in that wallet?
    – Jonas H.
    Mar 13 at 11:17
  • Whoops, you're right! Seems I didn't realise I'd moved too much sol out of the wallet. Right now it just fails... is there some way for me to let the user know if they have insufficient balance for a transaction as the error messaging isn't super clear?
    – Steve F
    Mar 13 at 11:28
  • Yes. A better UX would be adding a balance check of the 'source' wallet in your UI before sending a transaction.
    – beeman
    Mar 13 at 13:52

1 Answer 1

0

Looks like this is failing because there is not enough sol in the wallet to pay for the fees and the new account.

To solve this you can use

 let balance = await connection.getBalance(feePayer.publicKey);
  console.log(`${balance / LAMPORTS_PER_SOL} SOL`);

And show a warning popup to the user in case he does not have enough sol.

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.