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.1 Answer
Reset to default 0it 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
版权声明:本文标题:TokenAccountNotFoundError Solana - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736628343a1945723.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论