Build & Deploy a “Hello World” Solana Program

Create, deploy, and call your first on-chain Solana program using Rust and Alchemy RPC

This guide walks you through building, deploying, and calling a minimal Solana on-chain program using Rust and Alchemy’s Solana RPC.
If you’re new to Solana development, this is the perfect first step to validate your toolchain and RPC setup.


Overview

In this tutorial, you will:

  1. Install Solana + Rust tooling
  2. Scaffold a new Rust program
  3. Write a modern, minimal Solana program
  4. Build it to BPF
  5. Deploy to devnet
  6. Invoke it with a TypeScript client using Alchemy RPC
  7. View logs proving the program ran correctly

Prerequisites

✔ Rust & Cargo

$curl https://sh.rustup.rs -sSf | sh

✔ Solana CLI

$cargo install solana-cli

✔ Node.js + Yarn or PNPM

$npm install -g pnpm

✔ Alchemy Solana RPC URL

From Alchemy dashboard → Create AppSolanadevnet.


Step 1: Create a new Solana program

$mkdir solana-hello-world
>cd solana-hello-world
>cargo new --lib hello_world

Step 2: Add Solana dependencies

Open Cargo.toml and replace the contents with:

1[package]
2name = "hello_world"
3version = "0.1.0"
4edition = "2021"
5
6[lib]
7crate-type = ["cdylib"]
8
9[dependencies]
10solana-program = "1.18.0"

Step 3: Write the Hello World program

Put this into src/lib.rs:

1use solana_program::{
2 account_info::{next_account_info, AccountInfo},
3 entrypoint,
4 entrypoint::ProgramResult,
5 msg,
6 pubkey::Pubkey,
7};
8
9entrypoint!(process_instruction);
10
11fn process_instruction(
12 _program_id: &Pubkey,
13 accounts: &[AccountInfo],
14 _instruction_data: &[u8],
15) -> ProgramResult {
16 let accounts_iter = &mut accounts.iter();
17 let signer = next_account_info(accounts_iter)?;
18
19 msg!("👋 Hello, Solana from Alchemy!");
20 msg!("Invoked by signer: {}", signer.key);
21
22 Ok(())
23}

Step 4: Build the program

$cargo build-sbf

To test this command was successful, run ls target/deploy - this should output something similar to:

$hello_world.so
>hello_world-keypair.json

Step 5: Create a Solana keypair

$solana-keygen new

You’ll get:

$Wrote new keypair to /Users/al/.config/solana/id.json
>========================================================================
>pubkey: 7QGE8McfeCHgm12Q8VN6jgBKqbbVdKpq5YiQrTyiMiNJ
>========================================================================

This wallet will pay for your deployments!


Step 6: Set your network to devnet

Use Alchemy:

$solana config set --url https://solana-devnet.g.alchemy.com/v2/Pq8ZtHk2Gf3J4BH30ru_k

Your terminal will output a confirmation message. ✅


Step 7: Airdrop SOL

$solana airdrop 0.2

Note: You may get a rate-limit error. If you do and need more devnet funds, try the official Solana faucet.


Step 8: Deploy your program

$solana program deploy target/deploy/hello_world.so

Your terminal will output something like:

$Program Id: Eq5z52U3gGZNHVhgR1bgba8deMgtuFkpUNzd8iBsKvwJ
>
>Signature: yhJxt2ovd3SzGRZbhTkWajkA3uvhX8iqLzuWSrPYyW6AAqZjD2Vq1ApxSAUS5ywQyUnwDwPG8vqKpJv1wgAUFwo

Step 9: Invoke program via Alchemy RPC

1import {
2 Connection,
3 PublicKey,
4 Keypair,
5 Transaction,
6 TransactionInstruction,
7} from "@solana/web3.js";
8
9const ALCHEMY_RPC = "https://solana-devnet.g.alchemy.com/v2/YOUR_KEY";
10const PROGRAM_ID = new PublicKey("YOUR_PROGRAM_ID");
11
12async function main() {
13 const connection = new Connection(ALCHEMY_RPC);
14
15 const payer = Keypair.generate();
16 await connection.requestAirdrop(payer.publicKey, 1e9);
17
18 const ix = new TransactionInstruction({
19 programId: PROGRAM_ID,
20 keys: [{ pubkey: payer.publicKey, isSigner: true, isWritable: false }],
21 data: Buffer.alloc(0),
22 });
23
24 const tx = new Transaction().add(ix);
25 const sig = await connection.sendTransaction(tx, [payer]);
26
27 console.log("Transaction signature:", sig);
28
29 const logs = await connection.getTransaction(sig, {
30 commitment: "finalized",
31 });
32
33 console.log("Program logs:", logs?.meta?.logMessages);
34}
35
36main();

🎉 Success

You now have a working Solana program deployed on Solana devnet!

Check out the next guide on how to:

  1. set up a frontend for this program
  2. invoke it using Alchemy 🚀