Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions basics/close-account/anchor/README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
# Destroy an Account
# Close an Account

1. We're creating a `PDA` using [create_user.rs](programs/destroy-an-account/src/instructions/create_user.rs)
1. We're creating a `PDA` using [create_user.rs](programs/close-account/src/instructions/create_user.rs)
instruction.

```rust
#[account(
init,
seeds=[User::PREFIX.as_bytes(), user.key().as_ref()],
payer=user,
space=User::SIZE,
space=UserState::INIT_SPACE,
seeds=[b"USER", user.key().as_ref()],
bump
)]
pub user_account: Box<Account<'info, User>>,
pub user_account: Account<'info, UserState>,
```

2. We're closing it using [destroy_user.rs](programs/destroy-an-account/src/instructions/destroy_user.rs)
instruction, which uses `Anchor` `AccoutClose` `trait`.
2. We're closing it using [close_user.rs](programs/close-account/src/instructions/close_user.rs)
instruction, which uses the `close` account constraint to close the account and return its
lamports to `user`.

```rust
user_account.close(user.to_account_info())?;
#[account(
mut,
seeds=[b"USER", user.key().as_ref()],
bump=user_account.bump,
close=user, // close account and return lamports to user
)]
pub user_account: Account<'info, UserState>,
```

3. In our test [destroy-an-account.ts](tests/destroy-an-account.ts) we're using `fetchNullable` since we expect
the account to be `null` prior to creation and after closing.
3. In our test [test.ts](tests/test.ts) we're using `fetchNullable` after closing the account,
since a closed account no longer exists and should resolve to `null`.

```typescript
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);
const userAccount = await program.account.userState.fetchNullable(userAccountAddress);
assert.equal(userAccount, null);
```
2 changes: 1 addition & 1 deletion basics/favorites/anchor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This is a basic Anchor app using PDAs to store data for a user, and Anchor's account checks to ensure each user is only allowed to modify their own data.

It's used by the [https://github.com/solana-developers/professional-education](Solana Professional Education) course.
It's used by the [Solana Professional Education](https://github.com/solana-developers/professional-education) course.

## Usage

Expand Down
2 changes: 1 addition & 1 deletion tokens/token-2022/nft-meta-data-pointer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ The project uses session keys (maintained by Magic Block) for auto approving tra

Many casual games in traditional gaming use energy systems. This is how you can build it on chain.

If you have no prior knowledge in solana and rust programming it is recommended to start with the Solana cookbook [Hello world example](<[https://unity.com/](https://solanacookbook.com/gaming/hello-world.html#getting-started-with-your-first-solana-game)>).
If you have no prior knowledge in solana and rust programming it is recommended to start with the Solana cookbook [Hello world example](https://solanacookbook.com/gaming/hello-world.html#getting-started-with-your-first-solana-game).

## Anchor program

Expand Down
2 changes: 1 addition & 1 deletion tokens/transfer-tokens/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Just like with minting, transfers of SPL Tokens are conducted between Associated

You can use the `transfer()` function provided by the SPL Token Program to conduct a transfer of any SPL Token with the appropriate permissions.

Check out [SPL Token Minter](../spl-token-minter) or [NFT Minter](../nft-minter) to learn more about Associated Token Accounts.
Check out [Create an SPL Token](../create-token) and [NFT Operations](../nft-operations) for related token creation and NFT examples.
Loading