3

If I have an account that's passed into my anchor program, I can get its bump by doing

let acc_bump = ctx.bumps(ctx.accounts.my_account);

Is there something equivalent if I want to know the current size of an account?

1 Answer 1

5

You can do some variation of the following snippets to get the byte length of an account passed into an instruction

let acc_info = ctx.accounts.my_account.to_account_info().data_len(); // will return a usize
let account = ctx.accounts.my_account.clone().into_inner();

let account_size = (account.try_to_vec()?).len(); // will return a usize
1
  • Just what I was looking for, thanks!
    – Ahri
    Commented Mar 20 at 9:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.