Solana Program Interaction Toolkit (Web3.js CLI Project)
Build a TypeScript CLI toolkit using @solana/web3.js to query accounts, send transactions, decode data, and analyze logs without relying on Anchor.
This project does not involve writing Solana smart contracts. Instead, you're building tools to interact with them, which is a key skill for frontend devs, indexers, or tooling engineers.
What You’ll Build
By the end of this project, you will:
- Write scripts to connect to devnet and read account state
- Send custom transactions using
@solana/web3.js - Query program accounts and decode their data
- Fetch transaction logs and simulate transactions
Requirements
- Node.js installed
- A funded keypair (
solana-keygen new+solana airdrop) - TypeScript + basic CLI project setup
- Installed
@solana/web3.js
npm install @solana/web3.jsSuggested Toolkit Features
You don’t need to build all of these; pick at least 3 to implement fully.
Sample Snippets
Here are some examples you can adapt.
Connect to Devnet
import { Connection, clusterApiUrl } from "@solana/web3.js";
// Using public devnet endpoint
const connection = new Connection(clusterApiUrl("devnet"), "confirmed");
// Alternative: Use a premium RPC provider for production
// const connection = new Connection("https://your-rpc-endpoint.com", "confirmed");Fetch Account Info
import { PublicKey } from "@solana/web3.js";
const pubkey = new PublicKey("...");
const info = await connection.getAccountInfo(pubkey);
console.log({
lamports: info?.lamports,
owner: info?.owner.toBase58(),
executable: info?.executable,
dataLength: info?.data.length
});Project Steps
Step 1: Scaffold the CLI
Create a basic Node.js/TypeScript project with one command per file (e.g., send.ts, info.ts). Use ts-node or esbuild-runner to run.
Step 2: Implement Script Logic
Use @solana/web3.js to write CLI tools that can connect, fetch data, and send transactions.
Step 3: Test on Devnet
Use solana airdrop to get funds and run your tools against devnet programs or accounts.
Step 4: Add Flags or Arguments
Use process.argv or libraries like yargs to pass CLI arguments (e.g., --to, --amount, --program-id).
Common Pitfalls
Missing await
Most @solana/web3.js methods are async. Be sure to await or use .then() to get actual results.
Wrong cluster or account
Double-check that you're connecting to the correct cluster (devnet, not mainnet) and using valid base58-encoded keys.
Data decoding mismatch
If you’re decoding account data manually, ensure your buffer layout matches the on-chain structure exactly.
Summary
This project introduced you to interacting with Solana programs and accounts through the raw JavaScript SDK. By building your own CLI tooling, you now understand:
- How to read and write to the Solana blockchain from scripts
- What happens under the hood of wallets and UIs
- How to analyze account state and transaction logs
You can now extend these tools or reuse this structure for future indexing, simulation, or debugging work.
Solana Transaction Structure Explained (Beginner Friendly)
Understand Solana transaction structure, signers, instructions, recent blockhashes, and the full lifecycle from creation to confirmation and finality.
Solana Devnet Program Analysis Challenge
Reverse-engineer a Solana devnet program by tracing transactions, decoding accounts, and documenting instructions to build practical on-chain analysis skills.