Ayush a3b87a4948 update: tokens native, formatter, trigger action on project changes (#81) преди 1 година
..
migrations a3b87a4948 update: tokens native, formatter, trigger action on project changes (#81) преди 1 година
programs 905b445dc8 anchor basics working преди 1 година
tests a3b87a4948 update: tokens native, formatter, trigger action on project changes (#81) преди 1 година
Anchor.toml a70c93ba45 test: Adding test jobs github actions for anchor and solana native 💚 (#76) преди 1 година
Cargo.toml c30325a560 delete pnpm-lock.yaml files преди 1 година
README.md 1780636d2e close account example преди 2 години
package.json f116e3891a update to @coral-xyz/spl-token 0.30.0 преди 1 година
pnpm-lock.yaml cf3a9aa887 test adding back pnpm-lock.yaml преди 1 година
tsconfig.json 1780636d2e close account example преди 2 години

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);