On-Chain Key-Value Storage
An Anchor program that stores and updates user-defined key-value entries on-chain, a small favorites manager.
A Solana smart contract project that shows how to send, store and update data on-chain using keys. Written in Rust with the Anchor framework.
The project interacts with a Solana program by writing and updating user-defined data directly on-chain. It is a simple “favorites” manager: users send strings or numbers to the chain, associate them with a unique key, and update those entries later.
It is a good starting point for:
- Understanding persistent on-chain state
- Managing user-specific data using derived accounts
- Creating decentralized CRUD-style apps
Stack and tools
- Rust, for the Solana smart contract logic
- Anchor, the framework for Solana programs
- A local test validator
- Rust unit and integration tests
Features
- Send arbitrary data to the blockchain. Insert a value associated with a custom key.
- Update stored data by key. Modify entries via a transaction that targets a specific key.
- A simple chain storage pattern. Uses Solana accounts to persist user-defined values.
- Full test coverage. Rust-based tests validate the program logic locally.
Getting started
-
Start a local Solana validator:
solana-test-validator -
Build and deploy:
anchor build && anchor deploy -
Add your wallet:
export ANCHOR_WALLET=~/.config/solana/id.json -
Run the tests:
cargo test -
View the transactions at the local explorer: http://localhost:8899
Use cases
- Store favorite quotes, URLs or topics by key
- Use it as a base for decentralized note-taking or bookmarking
- Extend it with access control and per-user namespaces
License
This project is licensed under the MIT License, free for personal or commercial use.
Neighbors in time
Related: the posts that share this one's subject, and where the thread goes next.