Alchemy Logo

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.


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

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

cargo install solana-cli

npm install -g pnpm

From Alchemy dashboard → Create AppSolanadevnet.


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

Open Cargo.toml and replace the contents with:

[package]
name = "hello_world"
version = "0.1.0"
edition = "2021"
 
[lib]
crate-type = ["cdylib"]
 
[dependencies]
solana-program = "1.18.0"

Put this into src/lib.rs:

use solana_program::{
    account_info::{next_account_info, AccountInfo},
    entrypoint,
    entrypoint::ProgramResult,
    msg,
    pubkey::Pubkey,
};
 
entrypoint!(process_instruction);
 
fn process_instruction(
    _program_id: &Pubkey,
    accounts: &[AccountInfo],
    _instruction_data: &[u8],
) -> ProgramResult {
    let accounts_iter = &mut accounts.iter();
    let signer = next_account_info(accounts_iter)?;
 
    msg!("👋 Hello, Solana from Alchemy!");
    msg!("Invoked by signer: {}", signer.key);
 
    Ok(())
}

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

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!


Use Alchemy:

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

Your terminal will output a confirmation message. ✅


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.


solana program deploy target/deploy/hello_world.so

Your terminal will output something like:

Program Id: Eq5z52U3gGZNHVhgR1bgba8deMgtuFkpUNzd8iBsKvwJ
 
Signature: yhJxt2ovd3SzGRZbhTkWajkA3uvhX8iqLzuWSrPYyW6AAqZjD2Vq1ApxSAUS5ywQyUnwDwPG8vqKpJv1wgAUFwo

import {
  Connection,
  PublicKey,
  Keypair,
  Transaction,
  TransactionInstruction,
} from "@solana/web3.js";
 
const ALCHEMY_RPC = "https://solana-devnet.g.alchemy.com/v2/YOUR_KEY";
const PROGRAM_ID = new PublicKey("YOUR_PROGRAM_ID");
 
async function main() {
  const connection = new Connection(ALCHEMY_RPC);
 
  const payer = Keypair.generate();
  await connection.requestAirdrop(payer.publicKey, 1e9);
 
  const ix = new TransactionInstruction({
    programId: PROGRAM_ID,
    keys: [{ pubkey: payer.publicKey, isSigner: true, isWritable: false }],
    data: Buffer.alloc(0),
  });
 
  const tx = new Transaction().add(ix);
  const sig = await connection.sendTransaction(tx, [payer]);
 
  console.log("Transaction signature:", sig);
 
  const logs = await connection.getTransaction(sig, {
    commitment: "finalized",
  });
 
  console.log("Program logs:", logs?.meta?.logMessages);
}
 
main();

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 🚀
Was this page helpful?