Skip to main content
14 votes
Accepted

How can I increase an existing account size?

You can do this in Anchor with realloc* constraints. #[derive(Accounts)] pub struct Example { #[account(mut)] pub payer: Signer<'info>, #[account( mut, seeds = [b&...
sohrab's user avatar
  • 1,851
8 votes
Accepted

How to check if a PDA account has/hasn't been initialized?

Without constraints Check initialized Account::try_from will check the account is owned by the correct program the account is initialized the account has the correct discriminator and can be ...
Henry E's user avatar
  • 2,949
3 votes
Accepted

What is an "account revival attack"? Regarding the "#[account(close = <target_account>)]" constraint

In your Solana program the #[account] attribute for a data type assigns a unique 8-byte discriminator for accounts of that type. i.e: #[account] pub struct MyType {} When an account of that type is ...
Ademola's user avatar
  • 3,944
3 votes

How to check if a PDA account has/hasn't been initialized?

What "(de)initialized" looks like is up to your program. Typically it's a some combination of the assigned owner program, lamports balance, allocated data size and/or value(s) stored in the ...
trent.sol's user avatar
  • 4,585
3 votes
Accepted

Reducing calls to .load() in constraints

You might have to chain all your constraints into a single constraint. For example: #[account( mut, constraint = { let acc = some_acc.load()?; (acc.admin == *admin.key || acc....
Ademola's user avatar
  • 3,944
3 votes
Accepted

Is there a way I can use find_program_address used to derive a PDA as an anchor constraint

You can use the seeds and bump constraints, and then also specify the program that the pda should be derived from. For example: #[account( seeds = [b"some_seed"], bump, ...
john's user avatar
  • 7,794
2 votes
Accepted

Check for negative "unsign" interger does not work

rate is defined as u64, an unsigned 64-bit integer, meaning that the 8 bytes that make up the number will always be interpreted as unsigned, greater than or equal to 0. When you pass -10, that creates ...
Jon C's user avatar
  • 19.6k
2 votes
Accepted

Error Code: ConstraintMut. Error Number: 2000. Error Message: A mut constraint was violated.'

Just ran into the same error. The issue (in my case) was my IDL was out-of-sync with the program I invoking on dev-net. The program was expecting a mutable account but the IDL had the account marked ...
mrmizz's user avatar
  • 36
2 votes

What is an "account revival attack"? Regarding the "#[account(close = <target_account>)]" constraint

The idea is just that you can send solana to the closed accounts and revive them. Program accounts that have had all their lamports removed don't get their ownership transferred to the system program ...
Henry E's user avatar
  • 2,949
1 vote

Signer added when using has_one

The answer is actually on the TS side. If you are sending the tx from some specific user like so: const program = workspace.someProgram as Program<SomeProgram>; await admin.userProgram....
Whiteseal's user avatar
  • 3,607
1 vote

How to check if a PDA account has/hasn't been initialized?

Everyone here posted pretty good answers but without code to back it up, so I will probably end up going with my own answer now that I have figured this issue out. I realized that AccountInfo holds ...
TovarishFin's user avatar
1 vote

How to check if a PDA account has/hasn't been initialized?

There may be a better way to check if an account has been initialised, but personally I just check if it has lamports: if **destination_account_info.try_borrow_lamports()? > 0 { msg!("...
daoplays's user avatar
  • 597

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