9
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: ...
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 ...
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 ...
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. ...
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 ...
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 ...
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(...
4
votes
Accepted
How to received typed getTransaction response with jsonParsed encoding?
Despite you having asked the RPC to return you a parsed instruction, there's no guarantee that the RPC will be able to parse every instruction. Therefore, the type of the instruction is a union of ‘a ...
3
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
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::...
3
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, ...
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.
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.
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 ...
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(
...
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 ...
3
votes
getAssociatedTokenAddressSync returns different token account address than the one in solscan
This address is not the associated token account. If you see the initialization transaction at https://explorer.solana.com/tx/...
3
votes
Accepted
Spl Tokens deployed with Token 2022 program giving error during ATA creation with Solana/Web3.js
When getting the token account of a token22 token you need to add the token22 program id to the call:
export async function createAssociatedTokenAccount(
connection: Connection,
payer: Signer,
...
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 ...
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 ...
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
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 ...
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 ...
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 ...
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 ...
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 &...
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 ...
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 ...
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 ...
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.
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
spl-associated-token-account × 91spl-token × 61
spl-token-program × 27
associated-token-account × 22
solana-program × 17
anchor × 12
spl × 12
web3.js × 11
anchor-spl × 9
token × 8
rust × 6
token-2022 × 6
spl-token-cli × 5
associated-token-program × 5
anchor-lang × 4
wallet × 3
python × 3
ata × 3
solana-wallet-adapter × 3
transactions × 2
account × 2
rpc × 2
javascript × 2
typescript × 2
nextjs × 2