admin管理员组

文章数量:1124407

I'm trying to transfer a token from a backend wallet to another address, but I keep encountering the error: TokenAccountNotFoundError. I'm new to Solana and have been stuck on this issue for an entire day. I would greatly appreciate it if someone could take the time to help me out. Thank you in advance!

[INFO] Token Address: - "mntsMZSVHWeqHuKUbXX9JsusrThmYgJBAznxKqvyjd4"
[INFO] Payer PublicKey: - "5qZKg9G3yRMZeVRuuBiDNZpFAS2kKHeNWU49b9oiEgBV"
[INFO] Destination: - "9yXczYtdSC9kExkhMdPtX4u5526HunjEKzHtnMDJgTjW"

I have the addresses involved, in case they might help you.

async withdrawTokens(destinationAddress: string, amount: number): Promise<void> {
    try {
      const connection = this.getConnection();
      const payer = this.getPayer();
      const tokenAddress = this.getTokenAddress();

      const destination = new PublicKey(destinationAddress);

      const payerTokenAccount = await getOrCreateAssociatedTokenAccount(
        connection,
        payer,
        tokenAddress,
        payer.publicKey,
      );

      const destinationTokenAccount = await getOrCreateAssociatedTokenAccount(
        connection,
        payer,
        tokenAddress,
        destination,
      );

      const transaction = new Transaction().add(
        createTransferInstruction(
          payerTokenAccount.address,
          destinationTokenAccount.address,
          payer.publicKey,
          amount,
        ),
      );

      await sendAndConfirmTransaction(connection, transaction, [payer]);
    } catch (error) {
      logger.error(`Error during token account creation: ${error.stack}`);
      throw new BenignError(`Failed to execute Solana transfer: ${error.message}`);
    }
  }

Yes, i have this as I saw in other posts this.connection = new Connection(process.env.SOLANA_RPC_URL, 'confirmed');

I'm trying to transfer a token from a backend wallet to another address, but I keep encountering the error: TokenAccountNotFoundError. I'm new to Solana and have been stuck on this issue for an entire day. I would greatly appreciate it if someone could take the time to help me out. Thank you in advance!

[INFO] Token Address: - "mntsMZSVHWeqHuKUbXX9JsusrThmYgJBAznxKqvyjd4"
[INFO] Payer PublicKey: - "5qZKg9G3yRMZeVRuuBiDNZpFAS2kKHeNWU49b9oiEgBV"
[INFO] Destination: - "9yXczYtdSC9kExkhMdPtX4u5526HunjEKzHtnMDJgTjW"

I have the addresses involved, in case they might help you.

async withdrawTokens(destinationAddress: string, amount: number): Promise<void> {
    try {
      const connection = this.getConnection();
      const payer = this.getPayer();
      const tokenAddress = this.getTokenAddress();

      const destination = new PublicKey(destinationAddress);

      const payerTokenAccount = await getOrCreateAssociatedTokenAccount(
        connection,
        payer,
        tokenAddress,
        payer.publicKey,
      );

      const destinationTokenAccount = await getOrCreateAssociatedTokenAccount(
        connection,
        payer,
        tokenAddress,
        destination,
      );

      const transaction = new Transaction().add(
        createTransferInstruction(
          payerTokenAccount.address,
          destinationTokenAccount.address,
          payer.publicKey,
          amount,
        ),
      );

      await sendAndConfirmTransaction(connection, transaction, [payer]);
    } catch (error) {
      logger.error(`Error during token account creation: ${error.stack}`);
      throw new BenignError(`Failed to execute Solana transfer: ${error.message}`);
    }
  }

Yes, i have this as I saw in other posts this.connection = new Connection(process.env.SOLANA_RPC_URL, 'confirmed');

Share Improve this question edited 2 days ago Hugo Duarte asked 2 days ago Hugo DuarteHugo Duarte 112 bronze badges New contributor Hugo Duarte is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
Add a comment  | 

1 Answer 1

Reset to default 0

it seems that getOrCreateAssociatedTokenAccount can't create a new token address for some reason. Try manually transferring a small amount of tokens to a wallet whose address is not located. In this way, the address will be initialised on the network and will be available.

本文标签: TokenAccountNotFoundError SolanaStack Overflow