Skip to Content
๐ŸŒ Web3๐Ÿ“– Solanaโš™๏ธ Programs

โš™๏ธ Programs

Programs on Solana are the equivalent of smart contracts: on-chain, immutable code that processes instructions and reads/writes accounts. They are compiled to BPF bytecode and deployed with a fixed program ID.


๐ŸŽฏ Key Ideas

  • Instructions โ€” A single โ€œmethod callโ€: program ID + list of accounts + instruction data (often serialized with Borshย ).
  • Program ID โ€” The public key of the program; clients pass it in every instruction.
  • No internal storage โ€” State lives in accounts owned by the program, not in the program binary.

๐Ÿ“š Development Options

ToolDescription
Native (C/Rust)Solana SDKย ; maximum control
AnchorAnchorย  โ€” Rust framework with IDL, macros, and client codegen
SeahorsePython-like language that compiles to Solana programs

๐Ÿ“ Calling a Program (Client-Side)

You need: program ID, accounts required by the instruction, and instruction data (layout must match the program).

import { Connection, Keypair, PublicKey, Transaction, sendAndConfirmTransaction, } from "@solana/web3.js"; const connection = new Connection("https://api.devnet.solana.com"); const programId = new PublicKey("YourProgramId..."); // Build instruction (accounts + data depend on the program) const keys = [ { pubkey: account1, isSigner: true, isWritable: true }, { pubkey: account2, isSigner: false, isWritable: true }, ]; const data = Buffer.alloc(8); // example: 8-byte instruction discriminator + args // ... encode your instruction args (e.g. with borsh) const ix = { programId, keys, data, }; const tx = new Transaction().add(ix); const sig = await sendAndConfirmTransaction(connection, tx, [payerKeypair]); console.log("Signature:", sig);

With Anchor, you typically use the generated client and IDL so you donโ€™t hand-build keys and data:

import { Program, AnchorProvider } from "@coral-xyz/anchor"; import idl from "./idl/my_program.json"; const provider = new AnchorProvider(connection, wallet, {}); const program = new Program(idl, programId, provider); await program.methods .myInstruction(arg1, arg2) .accounts({ account1, account2 }) .rpc();

๐Ÿ”— Resources

Last updated on