Skip to content

Commit 43515d1

Browse files
committed
docs: comprehensive style pass
Modernizes contributor and example documentation across the repo. No code, test, or config changes — docs only. Highlights: - Modernized test guidance in CONTRIBUTING and per-example READMEs: pnpm, Biome, node:test via npx tsx, solana-kite, @solana/kit, Codama clients. Removed references to ts-mocha, mocha, anchor test with legacy validator, solana-test-validator, anchor.workspace, and program.methods.X().rpc(). - Added basics/realloc/README.md explaining AccountInfo::realloc is deprecated in favor of AccountInfo::resize (anchor#4526), while noting the #[account(realloc = ...)] macro constraint is unchanged. - Deletionist prose pass on the largest READMEs (token-swap, nft-operations, token-fundraiser, nft-meta-data-pointer, several transfer-hook examples). Removed filler phrases, dead Seahorse notes, and personal RPC notes; replaced with neutral guidance. - Markdown hygiene: one H1 per file, fenced code blocks now have language tags, trailing whitespace removed, double-blank-line runs collapsed, readme.MD/readme.md renamed to README.md. - Removed the pblock-list/pino/ duplicate subtree (52 files, ~5.7K lines). It was a byte-for-byte copy of the parent's program/, sdk/, and cli/ added accidentally in solana-developers#398 and renamed in solana-developers#461; neither copy was built by CI. - Updated stale URLs across the repo: solanacookbook.com → solana.com/docs|developers/cookbook, docs.anza.xyz transactions doc → solana.com/docs/core/transactions, docs.rs/solana-program system instructions → solana-system-interface crate (post-split), docs.pyth.network paths, github.com/febo/pinocchio → anza-xyz fork, github.com/magicblock-labs/gum-program-library → session-keys rename, and Metaplex Shank/Solita docs → GitHub repos (Metaplex retired the docs pages).
1 parent 0b6d96c commit 43515d1

108 files changed

Lines changed: 950 additions & 7701 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CONTRIBUTING.md

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,66 @@
11
# Contribution Guidelines
22

3-
Thank you for considering contributing to the Solana Program Examples repository. We greatly appreciate your interest and efforts in helping us improve and expand this valuable resource for the Solana developer community.
4-
5-
We believe that a welcoming and inclusive environment fosters collaboration and encourages participation from developers of all backgrounds and skill levels.
6-
7-
To ensure a smooth and effective contribution process, please take a moment to review and follow the guidelines outlined below.
3+
Thank you for considering a contribution to this repository. We welcome new examples, fixes, and improvements from the community.
84

95
## How to Contribute
106

11-
We welcome contributions in the form of code, documentation, bug reports, feature requests, and other forms of feedback. Here are some ways you can contribute:
12-
13-
- **Code Contributions:** You can contribute code examples in Rust that demonstrate various Solana program functionalities. You can also contribute improvements to existing examples, such as bug fixes, optimizations, or additional features.
7+
- **Code:** Add new examples or improve existing ones (bug fixes, optimizations, additional features).
8+
- **Bug reports, ideas, feedback:** Open an issue describing what you found or what you'd like to see.
149

15-
- **Bug Reports, Ideas or Feedback:** If you encounter any issues or have ideas for new examples, please submit a bug report or feature request. Your feedback is valuable and helps us improve the quality and relevance of the examples.
10+
## Project structure
1611

17-
## General coding and writing guidelines
12+
- Each example lives at `category/example-name/<framework>/`, e.g. `basics/counter/anchor/`.
13+
- Supported frameworks: `anchor`, `quasar`, `pinocchio`, `native`. Use the existing layout as a reference.
14+
- Tests live alongside the program in a `tests/` directory.
1815

19-
Please follow the [Contributing and Style Guide from the Developer Content Repo](https://github.com/solana-foundation/developer-content/blob/main/CONTRIBUTING.md).
16+
## Tooling
2017

21-
Specifically for code in this repo:
18+
- **Package manager:** `pnpm`. Commit `pnpm-lock.yaml`. Do not use yarn or npm here.
19+
- **Formatter / linter:** [Biome](https://biomejs.dev/). Run `pnpm fix` from the repo root before submitting a PR.
2220

23-
1. Use pnpm as the default package manager for the project. You can [install pnpm by following the instructions](https://pnpm.io/installation). Commit `pnpm-lock.yaml` to the repository.
21+
## Testing
2422

25-
2. Solana Programs written for the Anchor framework should be in directory [`anchor`](https://www.anchor-lang.com), Solana Native in [`native`](https://solana.com/developers/guides/getstarted/intro-to-native-rust), respectively.
26-
- Project path structure: `/program-examples/category/example-name/<framework_name>`
27-
- Project path structure example for anchor: `/program-examples/category/example-name/anchor`
23+
This repo uses an in-process test runtime — no local validator boot, no `solana-test-validator`, no `anchor test --validator legacy`.
2824

29-
3. Tests for Anchor and Solana native programs should be written with [solana-bankrun](https://kevinheavey.github.io/solana-bankrun).
25+
For Anchor and Quasar examples, tests are written in TypeScript and run with `node:test` via `tsx`:
3026

31-
4. For Solana native programs ensure adding these mandatory pnpm run scripts to your `package.json` file for successful CI/CD builds:
32-
33-
```json
34-
"scripts": {
35-
"test": "pnpm ts-mocha -p ./tests/tsconfig.test.json -t 1000000 ./tests/realloc.test.ts",
36-
"build-and-test": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./tests/fixtures && pnpm test",
37-
"build": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./program/target/so",
38-
"deploy": "solana program deploy ./program/target/so/program.so"
39-
},
27+
```bash
28+
npx tsx --test --test-reporter=spec tests/*.ts
4029
```
4130

42-
5. Test command for Anchor should execute `pnpm test` instead of `yarn run test` for anchor programs. Replace `yarn` with `pnpm` in `[script]` table inside [Anchor.toml file.](https://www.anchor-lang.com/docs/manifest#scripts-required-for-testing)
31+
The conventional `Anchor.toml` `[scripts]` entry is:
4332

44-
```
33+
```toml
4534
[scripts]
46-
test = "pnpm ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
35+
test = "npx create-codama-clients; npx tsx --test --test-reporter=spec tests/*.ts"
4736
```
4837

49-
6. TypeScript, JavaScript and JSON files are formatted and linted using
50-
[Biome](https://biomejs.dev/). Execute the following command to format and lint your code at the root of this project before submitting a pull request:
38+
The TypeScript tests use:
5139

52-
```bash
53-
pnpm fix
54-
```
40+
- [`solana-kite`](https://solanakite.org) for the connection, wallet creation, token mint helpers, PDA derivation, and `sendTransactionFromInstructions`.
41+
- [`@solana/kit`](https://solanakit.com) for the core types (`KeyPairSigner`, `Address`, `lamports`).
42+
- A [Codama](https://github.com/codama-idl/codama)-generated client (via `npx create-codama-clients`) for invoking the program instructions. Do **not** use `anchor.workspace` or `program.methods.X().rpc()`.
43+
44+
Native and Pinocchio examples may use `litesvm` directly from Rust where appropriate.
45+
46+
## Style
47+
48+
Write American English in prose (e.g. "behavior", "initialize", "favor"). Code identifiers stay as-is.
49+
50+
Other conventions:
5551

56-
7. Some projects can be ignored from the building and testing process by adding the project name to the `.ghaignore` file.
57-
When removing or updating an example, please ensure that the example is removed from the `.ghaignore` file
58-
and there's a change in that example's directory.
52+
- One H1 per markdown file.
53+
- Fenced code blocks include a language tag (` ```rust `, ` ```typescript `, ` ```bash `, ` ```toml `).
54+
- Use full words rather than abbreviations (`transaction`, not `tx` or `txn`; `account`, not `acc`).
55+
- Prefer `async`/`await` over `.then()`/`.catch()`.
56+
- Use `Array<T>` rather than `T[]` in TypeScript.
57+
- Avoid magic numbers — name or explain them.
58+
- Write "onchain" / "offchain" as single words (no hyphen).
5959

60-
## Code of Conduct
60+
## Excluding an example from CI
6161

62-
We are committed to providing a friendly, safe, and welcoming environment for all contributors, regardless of their background, experience level, or personal characteristics. As a contributor, you are expected to:
62+
Add the project path to `.ghaignore` to skip it during CI builds. If you remove or replace an example, update `.ghaignore` accordingly.
6363

64-
Be respectful and inclusive in your interactions with others.
65-
Refrain from engaging in any form of harassment, discrimination, or offensive behavior. Be open to constructive feedback and be willing to learn from others.
66-
Help create a positive and supportive community where everyone feels valued and respected.
64+
## Code of conduct
6765

68-
If you encounter any behavior that violates our code of conduct, please report it to the project maintainers immediately.
66+
Be respectful and inclusive. Constructive feedback only. Report any conduct issues to the maintainers.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Each example is available in one or more of the following frameworks:
88

99
- [⚓ Anchor](https://www.anchor-lang.com/) — the most popular framework for Solana development. Build with `anchor build`, test with `pnpm test` as defined in `Anchor.toml`.
1010
- [💫 Quasar](https://quasar-lang.com/docs) — a newer, more performant framework with Anchor-compatible ergonomics. Run `pnpm test` to execute tests.
11-
- [🤥 Pinocchio](https://github.com/febo/pinocchio) — a zero-copy, zero-allocation library for Solana programs. Run `pnpm test` to execute tests.
12-
- [🦀 Native Rust](https://docs.solana.com/) — vanilla Rust using Solana's native crates. Run `pnpm test` to execute tests.
11+
- [🤥 Pinocchio](https://github.com/anza-xyz/pinocchio) — a zero-copy, zero-allocation library for Solana programs. Run `pnpm test` to execute tests.
12+
- [🦀 Native Rust](https://docs.anza.xyz/) — vanilla Rust using Solana's native crates. Run `pnpm test` to execute tests.
1313
- [🧬 ASM](https://github.com/blueshift-gg/sbpf) — hand-written sBPF assembly built with the `sbpf` toolchain. Run `pnpm build-and-test` to build and test.
1414

1515
> [!NOTE]
@@ -25,7 +25,7 @@ Constant product AMM (x·y=k) — create liquidity pools, deposit and withdraw l
2525

2626
### Escrow
2727

28-
Peer-to-peer OTC trade — one user deposits token A and specifies how much token B they want. A counterparty fulfils the offer and both sides receive their tokens atomically.
28+
Peer-to-peer OTC trade — one user deposits token A and specifies how much token B they want. A counterparty fulfills the offer and both sides receive their tokens atomically.
2929

3030
[⚓ Anchor](./tokens/escrow/anchor) [💫 Quasar](./tokens/escrow/quasar) [🦀 Native](./tokens/escrow/native)
3131

basics/checking-accounts/README.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
# Checking Accounts
22

3-
Solana Programs should perform checks on instructions to ensure security and that required invariants
4-
are not being violated.
3+
Solana programs should check the instructions they receive to ensure security and to make sure required invariants hold.
54

6-
These checks vary and depend on the exact task of the Solana Program.
5+
The exact checks depend on what the program does. Common ones include:
76

8-
In this example we see some of the common checks a Solana Program can perform:
9-
10-
- checking the program ID from the instruction is the program ID of your program
11-
- checking that the order and number of accounts are correct
12-
- checking the initialization state of an account
13-
- etc.
7+
- Verifying that the `program_id` on the instruction matches your own program.
8+
- Verifying the order and number of accounts.
9+
- Checking the initialization state of an account.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# checking-account-asm-program
22

3-
Created with [sbpf](https://github.com/blueshift-gg/sbpf)
3+
A Solana SBPF assembly implementation, scaffolded with [sbpf](https://github.com/blueshift-gg/sbpf).
Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
11
# Destroy an Account
22

3-
1. We're creating a `PDA` using [create_user.rs](programs/destroy-an-account/src/instructions/create_user.rs)
4-
instruction.
5-
```rust
6-
#[account(
7-
init,
8-
seeds=[User::PREFIX.as_bytes(), user.key().as_ref()],
9-
payer=user,
10-
space=User::SIZE,
11-
bump
12-
)]
13-
pub user_account: Box<Account<'info, User>>,
14-
```
3+
1. A `PDA` is created using the [create_user.rs](programs/destroy-an-account/src/instructions/create_user.rs) instruction.
154

16-
2. We're closing it using [destroy_user.rs](programs/destroy-an-account/src/instructions/destroy_user.rs)
17-
instruction, which uses `Anchor` `AccoutClose` `trait`.
5+
```rust
6+
#[account(
7+
init,
8+
seeds = [User::PREFIX.as_bytes(), user.key().as_ref()],
9+
payer = user,
10+
space = User::SIZE,
11+
bump,
12+
)]
13+
pub user_account: Box<Account<'info, User>>,
14+
```
1815

19-
```rust
20-
user_account.close(user.to_account_info())?;
21-
```
16+
2. The account is closed in [destroy_user.rs](programs/destroy-an-account/src/instructions/destroy_user.rs), using Anchor's `close` helper on the account info:
2217

23-
3. In our test [destroy-an-account.ts](tests/destroy-an-account.ts) we're using `fetchNullable` since we expect
24-
the account to be `null` prior to creation and after closing.
18+
```rust
19+
user_account.close(user.to_account_info())?;
20+
```
2521

26-
```typescript
27-
const userAccountBefore = await program.account.user.fetchNullable(userAccountAddress, "processed");
28-
assert.equal(userAccountBefore, null);
29-
...
30-
...
22+
3. The test [destroy-an-account.ts](tests/destroy-an-account.ts) verifies that the account is null both before creation and after closing, via `fetchNullable`:
23+
24+
```typescript
25+
const userAccountBefore = await program.account.user.fetchNullable(userAccountAddress, "processed");
26+
assert.equal(userAccountBefore, null);
27+
// ...
3128
const userAccountAfter = await program.account.user.fetchNullable(userAccountAddress, "processed");
3229
assert.notEqual(userAccountAfter, null);
33-
```
30+
```

basics/counter/README.md

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
11
# Counter
22

3-
This example program allows anyone to create a counter and increment it.
4-
5-
Any counter can be incremented by any key.
6-
7-
## Note: Seahorse
8-
9-
Seahorse currently does not allow the program to initialize anchor
10-
accounts unless they are PDAs.
11-
12-
Seahorse example only allows users to increment the counter that corresponds to their public key.
13-
14-
3+
Anyone can create a counter and increment it. Any counter can be incremented by any key.

basics/counter/anchor/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Anchor Counter
22

3-
Anchor enforces init constraints that enforces good programming paradigms.
3+
Anchor enforces `init` constraints that nudge you towards good programming patterns.
44

5-
This means this program has an additional initialization instruction for `Counter`s that the Solana native program does not.
5+
This program has an additional initialization instruction for `Counter`s that the Solana native equivalent does not.

basics/counter/mpl-stack/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Counter: MPL Stack
22

3-
This example program is written using Solana native using MPL stack.
4-
3+
A Solana-native counter built using the MPL (Metaplex) stack.
54

65
## Setup
76

8-
1. Build the program with `cargo build-sbf`
9-
2. Compile the idl with `shank build`
10-
3. Build the typescript SDK with `yarn solita`
11-
- Temporarily, we have to modify line 58 in ts/generated/accounts/Counter.ts
12-
to `const accountInfo = await connection.getAccountInfo(address, { commitment: "confirmed" });` in order to allow the tests to pass. In the future versions of Solita, this will be fixed.
13-
4. Run tests with `yarn test`
7+
1. Build the program: `cargo build-sbf`
8+
2. Build the IDL: `shank build`
9+
3. Build the TypeScript SDK: `pnpm solita`
10+
- Temporary workaround: edit `ts/generated/accounts/Counter.ts` line 58 to
11+
`const accountInfo = await connection.getAccountInfo(address, { commitment: "confirmed" });`
12+
so that the tests pass. Future Solita versions will fix this.
13+
4. Run tests: `pnpm test`

basics/counter/native/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Counter: Solana Native
22

3-
This example program is written in Solana using only the Solana toolsuite.
3+
Counter written in Solana native, using only the Solana toolchain.
44

55
## Setup
66

7-
1. Build the program with `cargo build-sbf`
8-
2. Run tests + local validator with `yarn test`
7+
1. Build the program: `cargo build-sbf`
8+
2. Run the tests: `pnpm test`
99

1010
## Debugging
1111

12-
1. Start test validator with `yarn start-validator`
13-
2. Start listening to program logs with `solana config set -ul && solana logs`
14-
3. Run tests with `yarn run-tests`
12+
1. Start a test validator: `pnpm start-validator`
13+
2. Listen to program logs: `solana config set -ul && solana logs`
14+
3. Run the tests: `pnpm run-tests`

basics/counter/pinocchio/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Counter: Solana Pinocchio
22

3-
This example program is written in Solana using only the Solana toolsuite.
3+
Counter written using the Pinocchio framework, with only the Solana toolchain.
44

55
## Setup
66

7-
1. Build the program with `cargo build-sbf`
8-
2. Run tests + local validator with `yarn test`
7+
1. Build the program: `cargo build-sbf`
8+
2. Run the tests: `pnpm test`
99

1010
## Debugging
1111

12-
1. Start test validator with `yarn start-validator`
13-
2. Start listening to program logs with `solana config set -ul && solana logs`
14-
3. Run tests with `yarn run-tests`
12+
1. Start a test validator: `pnpm start-validator`
13+
2. Listen to program logs: `solana config set -ul && solana logs`
14+
3. Run the tests: `pnpm run-tests`

0 commit comments

Comments
 (0)