Skip to main content
7 votes

Creating an Associated Token Account via Solana Program

try using the init_if_needed constraint here's a Solpg reference you can test: https://beta.solpg.io/631a439777ea7f12846aee89 #[program] mod example { use super::*; pub fn initialize(ctx: ...
john's user avatar
  • 7,487
5 votes

Getting error while minting token to an account "Transaction simulation failed: Error processing Instruction 0: invalid account data for instruction"

Your program expects the token account to be initialized already. Are you initializing it before calling the instruction? If not then it should return the invalid account data error like it is doing ...
0xShuk's user avatar
  • 1,951
4 votes
Accepted

Is it possible to make an ATA in one instruction, then use that created ATA in the next instruction, in a single transaction?

You can get the address for the token account even if the token account doesn't exist yet. You would add both instructions to the same transaction. With token accounts, you would first need to check ...
john's user avatar
  • 7,487
4 votes

Is it possible to make an ATA in one instruction, then use that created ATA in the next instruction, in a single transaction?

The key thing is that token ATA is not fetched from chain, it is calculated, so it can be gotten even if it doesn't exist yet. Yes you absolutely can, the order of instruction is what matters here. ...
Syed Aabis Akhtar's user avatar
4 votes

Looking for implementation example of anchor_spl::token::initialize_account

The initialize_account function is to create a new Token Account. The account in the struct is the Token Account that is being initialized in the instruction Here's a solpg link for reference ...
john's user avatar
  • 7,487
4 votes

TokenAccountNotFoundError when sending SPL tokens in React

getOrCreateAssociatedTokenAccount takes a Signer as the second parameter, since it might require paying for the new account's rent. The first one succeeds because the account already exists, but the ...
Jon C's user avatar
  • 16.1k
4 votes

Passing two ATA's into a single function

In Anchor, there is nothing stopping you from passing two TokenAccounts: pub struct SomeContext<'info> { #[account(mut)] pub some_ata: Account<'info, TokenAccount>, #[account(...
Whiteseal's user avatar
  • 3,214
3 votes

Looking for implementation example of anchor_spl::token::initialize_account

Here's a Solpg example for how to create an associated token account in Anchor using init_if_needed https://beta.solpg.io/6317c4d1bb7e0b5f4ca6dfa2 use anchor_lang::prelude::*; use anchor_spl::...
john's user avatar
  • 7,487
3 votes
Accepted

Passing two ATA's into a single function

Solved - it appears to have been a stack size limit error, moving some accounts to heap via use of Box worked.
rumika howdie's user avatar
3 votes

Funding Native Mint: Sum of account balances before and after instruction do not match

I asked a similar question recently. You need to transfer the balance at the very end of your transaction, or at least after any Cross Program Invocation. See this github issue that explains why.
Vincent Berthier's user avatar
3 votes

InterfaceAccount<'_, TokenAccount> fails to create Associated Token Account

Your provided JS client code shows: await program.methods .createAta() .accounts({ /* .. */ userAta: getAssociatedTokenAddressSync(mint, user:USER.publickey), }); It should be: await ...
Joe C's user avatar
  • 1,086
3 votes
Accepted

Cross-program invocation with unauthorized signer or writable account. (I can't understand where I went wrong)

You've almost got it! Some of the parameters are incorrect for the call, so you should do: invoke(&spl_associated_token_account::instruction::create_associated_token_account( ...
Jon C's user avatar
  • 16.1k
3 votes
Accepted

Transfer specific token to and from a known account

This looks okay, What I would add is checking whether the holding account to_ata is initialized, If it's not you could use anchor associated_token constraints #[derive(Accounts)] pub struct ...
Jimii's user avatar
  • 3,770
2 votes

how to get owner of token account

Try largestAccountInfo.value.data.parsed.info.owner sorry it's not in py, but TS example: const tokenMint = "9ARngHhVaCtH5JFieRdSS5Y8cdZk2TMF4tfGSWFB9iSK"; const largestAccounts = await ...
OneFishTaco's user avatar
2 votes
Accepted

Failing to create associated token account in rust tests. It says insufficient account keys for instruction

I hit the same issue and found there is a difference in behaviour of solana validator versions. I worked against test validator in version 1.9.29 (developing on localhost). I was using the version of ...
chalda's user avatar
  • 1,392
2 votes
Accepted

Why is AssociatedToken Program not needed when using associated_token constraint in anchor?

You need the Associated Token Program when creating an ATA on the Rust end, but don't need it just to validate an ATA. So if the ATA was created earlier, or you create your ATAs on the client side, ...
Whiteseal's user avatar
  • 3,214
2 votes
Accepted

How can I use `instruction::recover_nested`?

If you haven't resolved this yet, I built a UI that attempts to recover nested ATAs: https://tools.blastctrl.com/spl-token-tools/recover-nested
pepeIKO's user avatar
  • 396
2 votes
Accepted

Sending USDC dev token not working until recepient wallet has >0 value of said token

You're likely getting an error because the recipient's token account for that specific mint hasn't been created. Below is an example for how to build a transaction and add an instruction to create a ...
john's user avatar
  • 7,487
2 votes
Accepted

Does one have to generate a special token address for USDT, USDC... when one generates a new address?

Hey yes for every token except native sol that you want to send you need to create a token account if it does not yet exists. Best is to use an associated token account which can be derived from the ...
Jonas H.'s user avatar
  • 5,787
2 votes

How do I transfer the SOL on my token account?

The process is clunky, but to get the additional SOL out of a token account, you need to move the USDC to another account, close the account to retrieve everything, recreate the account, then move the ...
Jon C's user avatar
  • 16.1k
2 votes
Accepted

Are addresses in Solana unique accross all the tokens?

In Solana, your wallet has an address and then can have N many associated token accounts that also have their own unique addresses that are derived from the combination of the parent wallet's address ...
m_callens's user avatar
  • 889
2 votes

Can you send Custom tokens and NFTs to a PDA account?

If you want your PDA to be able to receive and send SPL, you can have one instruction in your program for example. This instruction can deposit on the PDA (this is a classic SPL transfer, it can be ...
Swifty's user avatar
  • 428
2 votes
Accepted

Add spl-token balance to wallet balance context provider

You can easily add any token to your existing context. There are various ways to do this. I am using the most basic (using spl-token library): First import spl-token library: import * as token from &...
0xShuk's user avatar
  • 1,951
2 votes
Accepted

Is gas or fees required for creating an assosiate token account?

You'll need a little bit of SOL to pay the "rent" to create the token account, however this SOL can also be recovered when you close the token account. I believe its around 0.002 SOL
john's user avatar
  • 7,487
2 votes

Token-2022 extension enforcing immutable owner

Reassigning the owner of an ATA is antipattern -- many dapps just assume that a wallet's account for a token is the ATA, without checking that the owner is valid, so you could trick a dapp into using ...
Jon C's user avatar
  • 16.1k
2 votes

How can I recover SPL tokens from an account that is nested inside another ATA account?

Since your first USDC account is not an associated token account, it means that there is a private key associated with it, just like a wallet. Like any wallet, it can own other token accounts. You'll ...
Jon C's user avatar
  • 16.1k
2 votes

Do I have to explicitly create a USDC account to be able to receive USDC coins?

No, you do not. Sending some USDC to that address should do this for you. Most wallets will do this for you. Also, make sure that the signer has some sol to cover the tx fees.
Jimii's user avatar
  • 3,770
2 votes
Accepted

The data structure of an associated token account's data field

This is the layout: AccountLayout = struct<RawAccount>([ publicKey('mint'), publicKey('owner'), u64('amount'), u32('delegateOption'), publicKey('delegate'), u8('state'), ...
Serban's user avatar
  • 1,406
2 votes
Accepted

freeze_authority being null

The freeze authority is unique to each token mint, and if it is set to None then it is impossible to ever freeze or thaw a token account. If you want flexibility, you'll want to keep the freeze ...
Jon C's user avatar
  • 16.1k
2 votes
Accepted

How to set the token amount into the script

first you should check how many decimals is used for the said token. Once you have the correct amount of decimals, i never had any problem using something like 12067000000 for example if 9 decimals
Effe2's user avatar
  • 1,250

Only top scored, non community-wiki answers of a minimum length are eligible