1

I am getting an error

TypeError: connection.getAccountInfo is not a function
    at getAccount (account.ts:102:1)

in method getOrCreateAssociatedTokenAccount() my parameters are

const fromTokenAccount1 = await getOrCreateAssociatedTokenAccount(
          connection,
          publicKey,
          mint1,
          publicKey,
          signTransaction
        );

Mint is USDC mint address, publickey i am getting from useWallet() for the sender. connection is mainnet. Can please where I am doing wrong?

1 Answer 1

1

It looks like the Connection object is not available to the getOrCreateAssociatedTokenAccount method. You can verify this by doing console.log(connection) right before you pass it into the method.

One of the reasons this happens is if you use this method in a modal window, as this might be rendered outside of the Solana connection providers.

3
  • 1
    Yes, you are right. I was passing using const connection = WalletAdapterNetwork.Mainnet; now passing using const connection = new Connection( "https://solana-mainnet.g.alchemy.com/v2/IjcuUmymeTy65r4Z0KPaWfm7hsIC5OFK", "confirmed" ); and error gone. Commented Jan 29 at 16:21
  • Thanks for confirming Mohammad! Feel free to upvote my answer! 🙌
    – beeman
    Commented Jan 29 at 16:32
  • 1
    i am running low at reputations sorry man Commented Jan 29 at 18:56

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.