Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
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, ...
castle_chain's user avatar
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&...
breeze wang's user avatar
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: ...
breeze wang's user avatar
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. #...
breeze wang's user avatar
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: ...
FCT's user avatar
  • 3
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 ...
Nazar Havryliuk's user avatar
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 ...
woodland's user avatar
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 ...
woodland's user avatar
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 ...
0xwtf's user avatar
  • 3
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.
Jimii's user avatar
  • 7,672
4 votes
1 answer
431 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()],...
Matheus Baptistella's user avatar
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 ...
Maxareo's user avatar
  • 101
2 votes
2 answers
278 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 ...
Abhishek Faliya's user avatar
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: &...
breeze wang's user avatar
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<...
techiejd's user avatar
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 ...
breeze wang's user avatar
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 ...
denimcodes's user avatar
1 vote
1 answer
601 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 ...
breeze wang's user avatar
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' ...
breeze wang's user avatar
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()?;...
Whiteseal's user avatar
  • 3,597
1 vote
0 answers
219 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&...
Whiteseal's user avatar
  • 3,597
1 vote
1 answer
377 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 ...
Brian M.'s user avatar
  • 141
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: ...
Dhruv D Jain's user avatar
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 ...
alex's user avatar
  • 1
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 ...
mega_creamery's user avatar
1 vote
2 answers
219 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: #[...
mega_creamery's user avatar
3 votes
1 answer
353 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()...
mega_creamery's user avatar
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 ...
Abhishek Faliya's user avatar
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/...
Abhishek Faliya's user avatar
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 ...
Abhishek Faliya's user avatar
7 votes
2 answers
790 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: ...
rumika howdie's user avatar
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 ...
Gmer's user avatar
  • 85
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&...
SolDev's user avatar
  • 33
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 ...
Panchal Vedant's user avatar
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 ...
onurhb's user avatar
  • 113
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 ...
Mr.H's user avatar
  • 117
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 = &...
Yilmaz's user avatar
  • 1,264
0 votes
1 answer
634 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 ...
Burger Bob's user avatar
  • 1,506
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 ...
Rounak Naik's user avatar
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?
Rounak Naik's user avatar
0 votes
1 answer
198 views

Can solana accounts be made immutable?

I have recently started learning about solana development and realised that solana accounts created by solana programs are mutable. Is there any way we can make them immutable? Also can you please ...
Rounak Naik's user avatar
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 ...
Rounak Naik's user avatar
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....
Yilmaz's user avatar
  • 1,264
1 vote
1 answer
54 views

derive correct account inside a different anchor context

Let's say I have this CampaignCount account: #[account] pub struct CampaignCount { // I keep track of how many campaigns I have so far pub id: u32, } Imagine I need to refer to this in the ...
Yilmaz's user avatar
  • 1,264
3 votes
1 answer
641 views

Can Solana Accounts be accessed by any Solana Program using its address?

If I have a deployed Solana Program which creates some Solana accounts for storing data in it. Can these Solana accounts be accessed by any other Solana program using the account addresses? I am ...
Rounak Naik's user avatar
1 vote
0 answers
45 views

How to call another instruction from the same Anchor program (No CPI) [duplicate]

Is there a way to invoke an instruction within the same program? just for the sake of code reusability, I know we can achieve this easily with CPI when invoking different programs instructions, but I ...
Ander's user avatar
  • 1,005
2 votes
2 answers
481 views

AccountLoader for a struct from another Program

Say I have an account in Program A, and I know it looks like this: #[account(zero_copy)] pub struct SomeAcc { pub some_num: u32, } Now in my Program B, I copy and paste this struct exactly into ...
Whiteseal's user avatar
  • 3,597
1 vote
2 answers
515 views

How do you deal with a changing account state?

Let us suppose that you want to update an account state to include a new field. pub struct MyState { pub a: u8, pub new_field: u8 } This means that fetching and decoding the old accounts prior to ...
Burger Bob's user avatar
  • 1,506
2 votes
1 answer
133 views

Is it bad practice to have instruction parameters as a part of the PDA seed?

Let us suppose I have made a design, where I would be able to derive the PDA just by knowing the ID. So I have made a PDA that uses the inputted instruction ID parameter as a part of the seed. #[...
Burger Bob's user avatar
  • 1,506
1 vote
1 answer
229 views

How to handle multiple tokens + SOL in a payments program?

Context Depending on the item price in USD, users should be able to pay for items with different tokens/currencies (this is made possible with Switchboard Oracles). The payments then go towards a ...
Burger Bob's user avatar
  • 1,506