Anchor hello-world example
The Anchor hello-world example is a small Solana program fixture for checking verifiable builds through the Anchor framework. It combines an Anchor project configuration with a Cargo package so the build system can produce a deployable program and compare its executable hash with a known result.
Program purpose
The program in examples/…/lib.rs defines one Anchor instruction named initialize. That instruction writes Hello, world! to the program log and returns success. It does not read or change account state, so the fixture keeps program behavior simple while the verification process checks the build result.
The instruction uses an empty account context. This means the example exercises Anchor's instruction and account declaration model without adding application state or account rules that could hide the build-focused purpose.
References: examples/…/lib.rs• L1-16
Anchor project configuration
The Anchor configuration in examples/…/Anchor.toml connects the project to a local Solana cluster. It assigns the program ID Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS to hello_world and selects the local Solana wallet as the provider identity.
The configuration also enables feature resolution and keeps Anchor lint checks active. These settings make the project use the expected Anchor project rules when it is built or verified.
| Configuration area | Role in the fixture |
|---|---|
| Localnet program mapping | Associates the Cargo program with its deployed program ID |
| Provider | Selects the local cluster and wallet for Anchor operations |
| Feature settings | Controls dependency feature resolution and lint behavior |
References: examples/…/Anchor.toml• L1-12
Cargo project
The Cargo project packages hello_world as both a Rust library and a deployable C-compatible library. Its Anchor framework dependency supplies the program interface and the build conventions used by the fixture.
The feature set supports normal builds as well as cases where the entry point, IDL, or instruction log name must be omitted. The default feature set stays empty, while the idl-build feature connects IDL generation to Anchor's build support. Cargo metadata also identifies Solana CLI version 4.3.0 for the project toolchain.
The committed lock file records the resolved dependency graph. It is part of the build input when another run must reproduce the reference executable.
References: examples/…/Cargo.toml• L1-28 examples/…/Cargo.lock• L1-3 examples/…/Cargo.lock• L138-145 examples/…/Cargo.lock• L725-734
Verification fixture
The Anchor project is one of the local examples exercised by the verification tests. The test builds from examples/hello_world_anchor, reads target/deploy/hello_world.so, and compares its hash with the fixture value ec383d8f2c815a4855521f442af9470a2ab5a8e0fa61a36bd1463aa5a7e93134.
This check shows that the verification flow can handle an Anchor project as well as the standard and Pinocchio hello-world projects. The example programs page gives the wider comparison, while the standard hello-world example and Pinocchio hello-world example describe the sibling fixtures.
The diagram shows how the Anchor source and project inputs become the executable that the local verification check measures.
flowchart LR
A[Anchor source] --> C[Anchor Cargo project]
B[Anchor.toml] --> C
L[Cargo.lock] --> C
C --> D[Local Solana build]
D --> E[hello_world.so]
E --> F[Executable hash]
F --> G[Compare with expected fixture hash]
The expected hash confirms that the selected source and build inputs produce the known artifact. It does not prove that the program is safe or that the application meets a wider business need.
References: src/test.rs• L201-210 examples/…/lib.rs• L5-12 examples/…/Anchor.toml• L7-12 examples/…/Cargo.toml• L1-19
Framework comparison
The Anchor fixture shares the hello-world behavior with the other examples, but it expresses the program through Anchor's program and account declarations. This makes it useful for checking that verification supports a framework-managed Solana project rather than only a direct Solana SDK or low-level program interface.
| Fixture | Main development approach | Verification role |
|---|---|---|
| Anchor hello-world | Anchor framework | Checks an Anchor project and its local project configuration |
| Standard hello-world | solana-program API | Provides the conventional SDK baseline |
| Pinocchio hello-world | Pinocchio framework | Checks a project with a different program interface and toolchain path |
References: examples/…/lib.rs• L1-16 examples/…/Cargo.toml• L1-19 examples/…/Cargo.toml• L1-21
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the program ID in Anchor.toml and
declare_id!aligned. A mismatch can make Anchor operations target a different program. - Keep the Cargo package name, deployable output name, and verification executable path aligned.
- Recheck the expected executable hash when the Anchor version, feature set, dependency lock, or Solana CLI metadata changes.
- Keep the localnet provider settings aligned with the environment used to exercise the fixture.
- Update the parent example page and sibling links if the Anchor fixture's role or shared hello-world behavior changes.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
Anchor.toml and declare_id! use different program IDs | Anchor commands and the built program refer to different identities | Keep both declarations equal |
| Cargo dependencies or features change without a refreshed lock state | The build can produce a different executable from the reference fixture | Treat Cargo.lock and the manifest as one build input |
| The package or output name changes without a test-path update | Hash verification cannot find the expected hello_world.so | Keep Cargo names aligned with the local verification path |
| The local provider points to the wrong cluster or wallet | Anchor actions can run against the wrong deployment target | Use the configured localnet provider for this fixture |
| The source or toolchain changes while the expected hash stays fixed | The local verification check reports a hash mismatch | Rebuild the reference hash whenever build inputs change |
Key files
| File | Why to read it |
|---|---|
| examples/…/lib.rs | Defines the Anchor instruction and its minimal hello-world behavior |
| examples/…/Anchor.toml | Connects the project identity, localnet provider, and Anchor feature settings |
| examples/…/Cargo.toml | Defines the package outputs, Anchor features, dependency, and Solana CLI metadata |
| examples/…/Cargo.lock | Records the resolved dependency graph for a repeatable build |
| src/test.rs | Shows the local build target, executable path, and expected hash used for verification |
| docs/example-programs.md | Places the Anchor fixture beside the other hello-world verification examples |
| docs/hello-world-example.md | Explains the conventional Solana SDK comparison fixture |
| docs/pinocchio-hello-world-example.md | Explains the Pinocchio comparison fixture |