I am updating the values in a PDA, but it is not being updated

--> In structure, I am mentioning the PDA like this:
        seeds = [GAME_ACC_PREFIX.as_bytes(), winner.key().as_ref(), winner_nft.key().as_ref()],
    pub game_stake_account_winner: Box<Account<'info, GameStakeAccount>>,

--> Inside function, I have created a mut variable from this.
    let game_stake_account_winner = &mut ctx.accounts.game_stake_account_winner;

--> Here, I am assigning the new value to a variable in the PDA
    let new_battle_number = game_config.battle_number.checked_add(1).unwrap();
    msg!("new_battle_number: {}, ts: {}", new_battle_number, time);
    game_stake_account_winner.battle_number = new_battle_number;

After this transaction, when I check the PDA, the value of game_stake_account_winner.battle_number remains unmodified.

  • Ostensibly this all looks fine, you're setting stuff to mut and assigning the variable. My best guess would be that maybe you haven't updated your IDL and maybe the account isn't being passed in as mutable (although that would cause an error). I think you just need to play around with debugging this a bit more by making sure that everything you think is happening in the program function actually is happening.
    – Henry E
    Commented Oct 19, 2022 at 12:57
  • When you say "after this transaction", how long after? If it's too soon for your RPC request's commitment level, then you won't see the mutation.
    – HelmetFace
    Commented Oct 20, 2022 at 3:47
  • Thanks for your comments HenryE & HelmetFace I am able to figure out the issue but it was different, mentioning it in the answer part of the question. Commented Oct 20, 2022 at 4:04

1 Answer 1


I was able to figure out the issue:

I was taking these two accounts in the input:

pub game_stake_account_winner: Box<Account<'info, GameStakeAccount>>,
pub game_stake_account_most_killer: Box<Account<'info, GameStakeAccount>>,

And in my test, winner & most_killer were the same, so both these were referring to the same account.

And I was updating both of them in instruction, so change of one was being overwritten by the change in another account.

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.