I am running into the error, in my Anchor program:

[Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: sum of account balances before and after instruction do not match]

I am doing a spl-token transfer through CPI:

        Transfer {
            from: sender_token_account.to_account_info(),
            to: receiver_token_account.to_account_info(),
            authority: user.to_account_info(),

In the same transaction I am also reallocating the size of a PDA.

Anyone has a hint on how to avoid this error?

  • I dont think PDA reallocation has anything to do with this error. Can you explain more on the changes happening in this code
    – Pratik.js
    Commented Nov 23, 2022 at 14:51
  • I am doing two things: 1. Transfer SPL Tokens 2. Reallocate PDA account I tried to do them separately, then both work fine. But combining them in one function is throwing this error
    – Nelis.sol
    Commented Nov 23, 2022 at 15:56
  • Please post the full instruction logic. There's not enough information in the provided sample to debug why the account balances would be off. Commented Nov 23, 2022 at 16:27

2 Answers 2


I solved the same problem here:


Be very careful when making transactions. Put the native ones first and then the one you use with pda

If my contribution does not help you, I invite you to share the code to solve it.


Did you solve this? I am having the exact same issue.

I am able to realloc (increase and decrease) if I remove the token transfer code in the instruction. I'm also able to do the token transfer by itself if I remove the realloc.

But if I combine them both I can only increase the PDA's size, not decrease, and I get the same error [Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: sum of account balances before and after instruction do not match].

use anchor_spl::{
  token::{self, Mint, Token, TokenAccount, Transfer as SplTransfer},

#[instruction(description: String)]
pub struct EditProfile<'info> {
  pub owner: Signer<'info>,

  pub token_mint: Account<'info, Mint>,

    associated_token::mint = token_mint,
    associated_token::authority = owner,
  pub owner_ata: Account<'info, TokenAccount>,

  #[account(mut, seeds = [b"user", owner.key().as_ref()], bump)]
  pub user: Account<'info, User>,

    payer = owner,
    associated_token::mint = token_mint,
    associated_token::authority = user,
  pub user_ata: Account<'info, TokenAccount>,

    seeds = [b"profile", owner.key().as_ref()],
    realloc = 8 + Post::BASE_SIZE + description.len(),
    realloc::payer = owner,
    realloc::zero = false,
  pub profile: Account<'info, Post>,

  pub system_program: Program<'info, System>,
  pub token_program: Program<'info, Token>,
  pub associated_token_program: Program<'info, AssociatedToken>,
  pub rent: Sysvar<'info, Rent>,

pub fn edit_profile(
  ctx: Context<EditProfile>,
  description: String,
) -> Result<()> {
  let profile = &mut ctx.accounts.profile;


  // instruction works if this is removed:
      SplTransfer {
        from: ctx.accounts.owner_ata.to_account_info(),
        to: ctx.accounts.user_ata.to_account_info(),
        authority: ctx.accounts.owner.to_account_info(),


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.