All Questions
85 questions
0
votes
1
answer
92
views
why "Transaction references a signature that is unnecessary" warning, and value of 'isSigner' is false in IDL?
I was playing with counter program in program-example repo.
When run test, I got warning: Transaction references a signature that is unnecessary, only the fee payer and instruction signer accounts ...
2
votes
1
answer
23
views
Can Other Programs Write to PDA Accounts even if the `Account` type is used and the ownership is checked?
Question: Ownership and Write Permissions for PDA Accounts in Solana Programs
I’ve been exploring how the #[account] macro in the Anchor framework interacts with the ownership model of PDA accounts, ...
1
vote
1
answer
418
views
What's the difference between Anchor Accounts and account attributes?
When looking at the docs it seems that both Accounts and account attributes are useful for account serialization, deserialization, and validation. Furthermore, Accounts seems to be a derive attribute ...
3
votes
3
answers
321
views
Extending struct fields in a PDA and ensuring compatibility
I need to extend the fields I have within a PDA. Some accounts are already live, so I want those to still be compatible with the new layout. As a simple illustrative example, consider this account ...
3
votes
1
answer
2k
views
How to close a PDA account?
#[account(
init,
seeds =
[
b"config".as_ref(),
mint.key().as_ref(),
],
bump,
payer = sender,
space = 90
...
5
votes
2
answers
2k
views
How do I fix 'please minimize large stack variables' error while testing my anchor program?
I'm getting the following error using Anchor 0.25.0 Stack offset of 11792 exceeded max offset of 4096 by 7696 bytes, please minimize large stack variables initializing my accounts on local testing.
I'...
2
votes
1
answer
72
views
how to get an token account's Mint address on chain?
In my anchor program, I declare a uncheck account that will check by code inside instruction function
/// CHECK: do check inside function.
#[account(mut)]
pub user_ata: UncheckedAccount&...
1
vote
2
answers
108
views
how can anchor program A read account data from anchor program B with #account macro way?
My anchor program "A", expect to use data from a anchor program name "B".
Let's say program_b (which I don't have code, just know it's address) has declare PDA account data struct:
...
0
votes
1
answer
34
views
Why my Option account is required when invoke from js client?
all.
I am trying to use Option account in a demo, where, token related accounts are optional, when not provided, it will transfer SOL from my contract to user, other wise transfer SPL token to user.
#...
0
votes
1
answer
29
views
will it fail if the program tried to create an account with the same seeds multiple times , although the bump exists ? using anchor
#[account(
init,
seeds = [
AMM_CONFIG_SEED.as_bytes()
],
bump,
payer = admin,
space = 8 + AmmConfig::INIT_SPACE,
)]
pub amm_config: ...
0
votes
1
answer
45
views
Is it possible to set up an account to point to another account?
I'm making an anchor program where I would like to make a user ID easily retrievable with their Pk, sequential ID or username. one way I thought is to make a PK link account (in case the seed for the ...
0
votes
0
answers
41
views
Can I use anchor address constraint with dynamic value from state
Here is the example of how address constraint is implemented, but the address is CONSTANT
https://beta.solpg.io/66b37272cffcf4b13384d2aa
I want to be able to change the authority who signs the ...
2
votes
1
answer
106
views
What exactly are `Interface<'info, T>` and `InterfaceAccount<'info, T>`
InterfaceAccount<'info, T> and Interface<'info, T> and Anchor accounts types
Would love to know more about them, where I should use them and what differentiates the two.
4
votes
3
answers
576
views
"Signature verification failed" error while creating an account
I am trying to create an account but I get an error while creating it.
const provider = anchor.AnchorProvider.env();
anchor.setProvider(provider);
const newAccountKeypair = anchor.web3.Keypair....
3
votes
1
answer
801
views
what is anchor #[instruction()] macro?
I have this code:
#[derive(Accounts)]
#[instruction(campaign_id: u32)]
pub struct CreateCompaign<'info> {
#[account(
mut,
seeds = [SEED.as_bytes(), &campaign_id....
1
vote
1
answer
59
views
Avoid unnecessary account generation
For context, I am trying to implement a contract I have on solidity to solana.
On solidity, I have a function like this, which writes data to state based on a condition.
function handleMessage(bytes ...
0
votes
1
answer
50
views
Mutate account data of a program by another program
I have a sender program, and a receiver program. What I want to do is,
sender program has a account, data_account. I want sender program to call modify_data of receiver program, which in turn mutates ...
0
votes
1
answer
27
views
How do I allow two different signers to modify data in a PDA?
I'm trying to understand PDAs and ultimately want to be able to have a game where two different players (each with their own wallet) can modify the game state individually (i.e. one signer). For this ...
4
votes
1
answer
435
views
How to use realloc to increase account space in Anchor?
Lets say that I have the following account struct for my instruction:
#[derive(Accounts)]
pub struct IncreaseDataSize<'info> {
#[account(
mut,
seeds = [signer.key().as_ref()],...
0
votes
1
answer
70
views
Who gets to create token associated accounts on Solana?
I understand the differences between token mint accounts and token associated accounts. As I'm building a web-app allowing people to mint spl tokens on our website, we are facing a question about who ...
2
votes
2
answers
279
views
Zero_copy not working , Getting `Zeroable` is not implemented for `[Event; 25000]`, while trying example
I'm trying This example by anchor to initialize large accounts and using zero_copy on them.
https://github.com/coral-xyz/anchor/blob/master/tests/zero-copy/programs/zero-copy/src/lib.rs#L156-L165
I'm ...
0
votes
1
answer
86
views
why "Error: memory allocation failed, out of memory" error?
I have a program that use to store configuration, as show bellow.
All work well except that, 'set_fee' function throw error:
> Program logged: "Instruction: SetFee"
> Program logged: &...
2
votes
1
answer
85
views
Is there a way to store a reference to a zero copy account in a regular account?
Is there a way to store reference to a zero copy account in a regular account? Something like
#[account]
pub struct HoldingAccount {
[account(zero)]
pub myReferenceToAZeroCopyAccount: Box<...
0
votes
0
answers
26
views
Possible to accept/pass in a list of accounts to program API? [duplicate]
pub struct Example<'info>{
pub mint: Account<'info, Mint>,
pub system_program: Program<'info, System>,
pub token_program: Program<'info, Token>,
pub rent: ...
0
votes
0
answers
14
views
Error when trying to update an account on Solana built with anchor
Here's the error I am getting:
Link to transaction: https://explorer.solana.com/tx/5LSyn7NfjK4me56nU8fiYVb9RGXCe7AJ7MBFYKBfcvxh35sLN9krkYU7fFLTJWWW6iz3aTpu3K4kXdhwAb8kydEq?cluster=devnet
Here's the ...
1
vote
0
answers
220
views
Account:try_from with different Anchor versions
I have a program which is on 0.28.0, and it uses an 0.26.0 dep. It builds without issue. Let's say the deps look like:
[dependencies]
anchor-lang = "0.28.0"
solana-program = "=1.16.23&...
1
vote
1
answer
602
views
what's the correct way to declare an account for program to receive and store SOL?
Demo bellowed is what I figure out to make program receive SOL. But it seem have room to improve, especially 'NewAccount', which look ugly, but I can't found property Account type to replace it. I ...
0
votes
1
answer
42
views
The data that anchor' account stored surprise me, for a non-PDA account, it store all history input data. Why?
I play this https://beta.solpg.io/62d67703f6273245aca4f5fe example days ago.
Just added more logs inside initialize() instruction.
After invoke initialize() multiple times with different 'new_account' ...
1
vote
1
answer
65
views
Reducing calls to .load() in constraints
When using constraints with a zero-copy account that uses AccountLoader, you can reduce acc.load() calls like:
#[account(
mut,
constraint = {
let acc = some_acc.load()?;...
1
vote
1
answer
379
views
Issues with Using AnchorSerialize and AnchorDeserialize Traits
so I'm looking to create an instruction that creates an account called GamePot that contains a field called TokenInfo that holds the data for what is meant to be any particular SPL token with a mint ...
3
votes
1
answer
70
views
How to allocate `Optional` accounts on heap?
I am trying to use optional accounts and since there are many accounts, i tried boxing them. But looks like the derive macro panics when i try to box the optional accounts like below.
escrow_account: ...
5
votes
1
answer
173
views
How to read account data in non owner program
If I deploy a program P1 which initialises a new account A1 and update the rvalue to for instance 9
#[derive(Accounts)]
pub struct Initialize<'info> {
#[account(init, payer = signer, ...
1
vote
2
answers
220
views
Are enums with associated values permitted?
Not sure if this is really an anchor or solana related question, since I am able to compile, just not to run tests.
I can run code and test against code that has an account that has following enum:
#[...
3
votes
1
answer
355
views
How do you repopen a closed account?
If an account has been closed with the following anchor context:
#[account(
mut,
close = user,
seeds = [
SEED_SCHEMA.as_bytes(),
&user.key().as_ref()...
1
vote
1
answer
1k
views
Can we change the owner of a Solana account?
I have a solana account created by a solana program deployed on the devnet. Is it possible to change the owner of the account? If yes then can you please tell how to do it?
1
vote
1
answer
489
views
"Access violation in stack frame 3 at address 0x200003ff0 of size 8 by instruction #35516" , even though I use zero copy on my account struct
This is my account struct
pub struct ClaimRewards<'info> {
#[account(init_if_needed, payer = payer, seeds = [OKUSEED.as_ref()], bump, mint::decimals = 6, mint::authority = mint)]
pub ...
1
vote
1
answer
108
views
Error: Invalid option while trying to fetch account data with anchor
I'm getting this error
Error: Invalid option endTime
at OptionLayout.decode (node_modules/@project-serum/borsh/src/index.ts:148:11)
at Structure.decode (node_modules/buffer-layout/lib/...
7
votes
2
answers
793
views
How to correctly read data from a Zero Copy account
I'm having trouble reading data in the client from a program with a zero copy account. I've defined the account as follows:
#[account(zero_copy)]
#[repr(packed)]
pub struct EventQueue {
header: ...
1
vote
1
answer
1k
views
Error: AnchorError: AnchorError caused by account: base_account. Error Code: AccountNotInitialized
I wrote a Solana Program with two functions, one for the initialization of an account and a second to upload data to the account. While testing on localhost it was working fine, but when I uploaded it ...
1
vote
0
answers
48
views
'Program failed to complete: Instruction passed to inner instruction is too large (12884933932 > 1280)', Getting this error [duplicate]
I'm getting this error
Program logged: "Instruction: CreateVester"
> Program consumed: 5565 of 200000 compute units
> Program returned error: "Instruction passed to inner ...
0
votes
1
answer
74
views
How to ensure unique u16 IDs for accounts?
I'm storing a vector of u16 user IDs. I decided not to store public keys in vector, which I can use as ids or get rid of ids completely instead, however public keys are 32 bytes and will have limited ...
3
votes
1
answer
282
views
Fetching transaction ID that created account
Background:
In my application I am creating an account to store some arbitrary information.
I then want to display the transaction id/address of the transaction that created such an account.
Question:
...
3
votes
1
answer
346
views
"Error processing Instruction 0: invalid program argument" while invoking method of other program using cpi
The callee program
#[program]
pub mod puppet {
use super::*;
pub fn initialize(_ctx: Context<Initialize>) -> Result<()> {
Ok(())
}
pub fn set_data(ctx: Context&...
2
votes
1
answer
317
views
How to create an account in any other program using CPI in which PDA is used as signer and payer
I just want to invoke initialize method of callee program from caller program in which pda account should be signer.
Callee Program
#[program]
mod callee {
use super::*;
// I want to call ...
3
votes
2
answers
515
views
Store text as string vs. bytes
Is there any advantage to using Vec<u8> over String to store text in storage account fields? And if so, why? From a storage perspective, they are nearly handled identically as far as I can tell ...
1
vote
1
answer
142
views
How to calculate space for an account dynamically using remaining_accounts
Is it possible to allocate space to an account based on account provided in remaining_accounts? I want to allocate enough space to store public key of the accounts provided in remaining_accounts in a ...
1
vote
1
answer
371
views
Can a closed account in anchor be initialised again?
I am following the soldev tutorials. At the Crossing Account and Revival attacks.The program has two methods a lottery initialisation account and a redeem tokens based on the time of entering. After ...
3
votes
1
answer
406
views
Why do we convert accounts to AccountInfo?
I have this rust function
pub fn purchase_ticket(ctx: Context<PurchaseTicket>, lottery_id: u32) -> Result<()> {
let lottery = &mut ctx.accounts.lottery;
let ticket = &...
0
votes
1
answer
635
views
How to use init_if_needed?
I want to create an instruction where it is only possible to initialize a new PDA account if some parameter on another PDA account (same type) is fulfilled. So I was thinking that init_if_needed would ...
0
votes
2
answers
2k
views
How to define a variable to a public key in anchor? [duplicate]
I want to hardcode a public key in my anchor Solana program and then compare it with the public keys passed to the functions of the program. Can someone please tell me how can I declare a variable ...