0

It won't create the Token Account, it says: Wallet or wallet owner is undefined.

I tried to change it to Wallet: wallet instead of Wallet: any.

  
  try {
    // const connection = new Connection('https://api.mainnet-beta.solana.com'); // Use this for mainnet
    const connection = new Connection(    "https://devnet.helius-rpc.com/?api-key=5d69c879-36f4-4acf-87b4-e44a64c07acc"    );
    const tokenAccount = await createAssociatedTokenAccount(
      connection,
      wallet.owner,
      new PublicKey(mintAddress),
      wallet.owner,
    );    
    console.log("Token account created: " + tokenAccount.toString());
    return tokenAccount.toBase58();
  } catch (error) {
    enqueueSnackbar("CreatetokenAccount Error creating token account: " + error, { variant: "error" });
    return "Error creating token account: " + error;
  } // //Error creating token account: TypeError: Cannot read properties of undefined (reading 'toBuffer')
};

//this is in function CreateToken22
  try {
        const tokenAccount = await createTokenAccount(wallet, mint.publicKey);
        if (!tokenAccount) {
          console.error('CreateToken22() - tokenAccount is undefined');
          return;
        }
        console.log("CreateToken22() - Token account: " + tokenAccount);
        const tokenAccountBuffer = bs58.decode(tokenAccount);//Breakpoint
        console.log("Token account buffer: " + tokenAccountBuffer);

        const mintResult = await mintToTokenAccount(wallet, mint.publicKey, tokenAccount, amount);
        console.log("CreateToken22() - Mint result: " + mintResult);
      } catch (error) {
        console.error('CreateToken22() - createSPl Error creating token account:', error);
        return;
      }

0

Your Answer

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