John 905b445dc8 anchor basics working 1 rok pred
..
migrations bbe74eee4d Upgrade to `@coral-xyz/anchor` 0.28.0 (#50) 2 rokov pred
programs 905b445dc8 anchor basics working 1 rok pred
tests d54727e782 update anchor basics examples 2 rokov pred
Anchor.toml d54727e782 update anchor basics examples 2 rokov pred
Cargo.toml f2d93baee1 add resolver = "2" to fix compile warning 1 rok pred
README.md 1780636d2e close account example 2 rokov pred
package.json f116e3891a update to @coral-xyz/spl-token 0.30.0 1 rok pred
tsconfig.json 1780636d2e close account example 2 rokov pred

README.md

Destroy an Account

  1. We're creating a PDA using create_user.rs instruction.

    #[account(
    init,
    seeds=[User::PREFIX.as_bytes(), user.key().as_ref()],
    payer=user,
    space=User::SIZE,
    bump
    )]
    pub user_account: Box<Account<'info, User>>,
    
  2. We're closing it using destroy_user.rs instruction, which uses Anchor AccoutClose trait.

    user_account.close(user.to_account_info())?;
    
  3. In our test destroy-an-account.ts we're using fetchNullable since we expect the account to be null prior to creation and after closing.

    const userAccountBefore = await program.account.user.fetchNullable(userAccountAddress, "processed");
    assert.equal(userAccountBefore, null);
    ...
    ...
    const userAccountAfter = await program.account.user.fetchNullable(userAccountAddress, "processed");
    assert.notEqual(userAccountAfter, null);