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
10 votes
Accepted

Is there a way to resize an account's data field?

From the anchor lang 25.0 docs, they have implemented the realloc constraint to give you access to the new functionality of resizing accounts. This functionality is particularly relevant for PDAs ...
Henry E's user avatar
  • 2,949
4 votes
Accepted

How can I determine a current size of Solana blockchain

This depends on your definition of what data is part of the blockchain and on your method to calculate that size. Data Categories Accounts, persistent data entries that programs own and access. Every ...
terorie's user avatar
  • 463
3 votes

What is the recommended way to calculate a account size, using sizeof or manually calculating it

For zero_copy accounts, you can use mem::size_of(). But for non-zero_copy accounts, the alignment is off and size_of() will give you a larger, incorrect space value. Instead you can do let acc = ...
hrs8's user avatar
  • 146
2 votes
Accepted

How to allot 1 bit space for boolean in Anchor program?

You can't - Solana charges rent in lamports per byte-year, meaning the minimum amount of storage you can rent is one byte anyway. More info on rent can be found here. Additionally, even if you could, ...
McBain's user avatar
  • 5,384
2 votes

How to have PDA space size depending on instruction argument

Found out you can use the #[instruction] macro, to use the args you're waiting for. Also the anchor docs says that the space needed for a String is 4 + length of string in bytes. So i'd do something ...
FluffyMuffin47's user avatar
2 votes
Accepted

Trait bound EnumStatus: anchor_lang::Space is not satisfied for Enum

You just need to add InitSpace to EnumStatus derives. - #[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Debug, Eq, PartialEq)] + #[derive(InitSpace, AnchorSerialize, AnchorDeserialize, Clone,...
Russo's user avatar
  • 349
1 vote

How to Calculate Space for PDA Accounts with Dynamic Vectors in Solana?

Are there any best practices for handling PDA accounts with dynamic data like vectors Best practice is don't do it. If you MUST have dynamically sized storage for whatever reason, use a statically ...
Whiteseal's user avatar
  • 3,597
1 vote

How to Calculate Space for PDA Accounts with Dynamic Vectors in Solana?

To answer your questions.... You'll need to just put some amount that you want to allocate at the start. Using std::mem::size_of will be incorrect, since it'll give you the stack space for a Vec, ...
Jon C's user avatar
  • 19.6k
1 vote
Accepted

How to calculate size of Option<String> for Anchor accounts

Hey there to calculate the size of an Option< String > when initializing an account in Anchor, you need to consider the size of the Option itself, which is always 1 byte, plus the size of the ...
beliveN DAOist.dev's user avatar
1 vote
Accepted

How to calculate space for an account dynamically using remaining_accounts

Should I just send the length of remaining_accounts as instruction data? This is the only way to do it, and then use that instruction data in the context macros with #[instruction(...)] The Context&...
m_callens's user avatar
  • 909
1 vote

Managing Space in the Zero Account

You can initialize it like this: #[account(init, payer=payer, space = 40 , seeds = [b"seeds".as_ref()], bump)] account_pda: Account<'info, AccountStruct> #[account] #[derive(...
user3688985's user avatar

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