Skip to content

Latest commit

 

History

History

anchor

README.md

Counter (Anchor)

Note

This is the Anchor v2 copy of this example. Every anchor command on this page needs the v2 CLI: cargo install anchor-cli --version 2.0.0-rc.1 --locked (avm has no prebuilt binary for this pre-release). The Anchor v1 version of this example is in ../anchor-v1.

Increment a global counter stored in a PDA. Anchor adds an explicit initialize_counter handler that the native variant handles differently.

See also: the repository catalog.

Major concepts

  • PDA seeds for global state
  • init vs mut account constraints
  • Instruction handlers: initialize and increment

Setup

From basics/counter/anchor/:

anchor build

Testing

anchor test

LiteSVM integration tests in programs/counter_anchor/tests/ call handlers and assert the stored count.

Usage

Inspect programs/counter_anchor/src/ for seeds and handler definitions.