Okay, look. Every other "deploy Solana smart contract" guide out there? They hit you with a wall of theory first. Like, 10 paragraphs on what Solana is, why it's fast, blah blah. You just want to deploy something that works, right? Not read a textbook. That's me. We'll skip the fluff. Jump straight in, build a real "hello world" thing, then level up. In my experience, that's how you actually learn - by doing, failing a bit, fixing it.
Why does this matter? 'Cause Solana's not Ethereum. No gas wars. Fees are like ~0.000005 SOL per signature. Super cheap. But mess up the CLI setup? You're stuck for hours. Sound familiar?
First things first. You need tools. NodeJS (v14+), NPM, latest Rust, Solana CLI (v1.7+ or whatever's current), and Git. Honestly, if you're on Windows, grab WSL Ubuntu. Makes life way easier - Rust compiles clean there.
apt update && apt upgradeapt install nodejs npmcurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh Then source $HOME/.cargo/envsh -c "$(curl -sSfL https://release.solana.com/v1.18.11/install)" (Check for latest version, yeah?)export PATH="/root/.local/share/solana/install/active_release/bin:$PATH"Test it. Run solana --version. See a number? Good. rustc --version. Same deal. If not, Google the error. Happens to everyone first time.
The thing is, M1 Mac users? Anchor might glitch. Install from source: cargo install --git https://github.com/project serum/anchor --tag v0.20.1 anchor cli --locked. Fixed it for me last week.
Now, clone the example. It's battle tested.
git clone https://github.com/solana labs/example helloworldcd example helloworldsolana config set --url https://api.devnet.solana.comsolana keygen new --force. Note the path it spits out. Passphrase? Make it simple for testing.solana airdrop 2. Might need twice - devnet faucet caps at 2 SOL. Check balance: solana balance. Need ~4 SOL total for deploys.npm install then npm run build:program rustsolana program deploy dist/program/helloworld.so. Grabs the exact path from build output.Boom. Program ID in your terminal. Copy it. Paste into Solana Explorer (devnet.solana.com). See it live? You're golden. Fees? Under 0.01 SOL usually.
lib.rs has the magic. It's Rust. Defines a GreetingAccount with a counter. Entrypoint function bumps it when called. Borsh for serialization - Solana's way of packing data tight. Don't sweat details yet. Just know it stores state in an account.
Deployed? Time to poke it.
npm install in the repo.npm run startOutputs connection, payer setup, then "Saying hello to [pubkey]". Runs a transaction. Check counter - increments each time. Run again. See it climb? That's your contract working on chain.
Potential issue: "Program needs to be deployed"? Means you skipped deploy or wrong ID. Fix: Re run deploy, note new ID if it changed. Or "No SOL"? Airdrop more. Devnet's free, just rate limited.
Hello world is cute. Real stuff? Anchor. It's like Rust + macros that handle boilerplate. Clients in TS too. I usually start projects with it now.
Clone this: git clone https://github.com/smartcontractkit/solana starter kit. Has Chainlink price feed example - pulls real oracle data.
cd solana starter kit && npm installsolana keygen new -o id.jsonsolana airdrop 2 (twice)solana address -k ./target/deploy/chainlinksolanademo keypair.jsonEdit lib.rs. Replace declareid! with your address, like declareid!("JC16qi56dgcLoaTVe4BvnCoDL6FhH5NtahA7jmWZFdqm");. Update Anchor.toml too if needed.
Build & deploy:
anchor buildanchor deploy --provider.cluster devnetProgram ID matches? Check explorer again.
Set env: Export ANCHORPROVIDERURL to devnet and wallet to your keypair.
Run: node client.js --program $(solana address -k ./target/deploy/chainlinksolanademo keypair.json) --feed HgTtcbcmp5BeThax5AU8vg4VwK79qAvAKKFMs8txMLW6
Creates account, calls execute RPC with Chainlink feed, system program. Logs transaction, then fetches price: "Price Is: X". Divide by DIVISOR (usually 10^8 or whatever the feed says).
In my experience, first run takes 10-20 secs. Confirmations matter - uses 'confirmed' commitment. Error like "Account not found"? Redeploy or check keypair.
| Problem | Why? | Fix |
|---|---|---|
| No SOL for deploy | Airdrop failed or drained | solana airdrop 2 x2. Or solana balance check. |
| Build fails on M1 | Anchor x86 only via npm | Manual cargo install from git tag v0.20.1. |
| "Program not found" | Wrong ID in client | Copy from deploy output. Verify on explorer. |
| High fees? Wait, no - but if mainnet | ~0.000005 SOL/sig + rent | Devnet free. Mainnet: Budget 0.1 SOL first deploy. |
| Rust errors galore | Version mismatch | rustup update stable. Rebuild. |
Okay, bored of examples? Make one. Use Anchor CLI: anchor init myproject. cd in, anchor build.
lib.rs structure:
Example counter instruction:
#[derive(Accounts)]
pub struct Increment<'info> { #[account(mut)] pub counter: Account<'info, Counter>, pub user: Signer<'info>, pub system_program: Program<'info, System>,
} pub fn increment(ctx: Context<Increment>) -> Result<()> { let counter = &mut ctx.accounts.counter; counter.count += 1; msg!("Count now: {}", counter.count); Ok(())
}
Build, deploy same as before. Client uses IDL (auto generated JSON) for TS calls. Pretty much plug and play.
Why Anchor? Handles serialization, account validation. Vanilla Rust? You write all that. Pain.
Don't deploy blind. Local validator.
solana test validator --log in new terminal.solana config set --url localhostsolana airdrop 10 (local gives plenty).anchor test - runs your tests against local.Fix bugs here. Fees zero. Speed: Instant blocks.
Devnet good? Switch: solana config set --url https://api.mainnet beta.solana.com.
Need real SOL. Buy on exchange, Phantom wallet, transfer to CLI keypair. First deploy? ~0.05-0.2 SOL depending on program size (rent exempt). Use solana program show <ID> post deploy to verify.
Pro tip: Upgrade programs later with solana program deploy --program id <old id> new.so. Buffer space needed upfront.
Accounts gotta be rent exempt. Calc with solana rent 100 (bytes). Signers pay.
PDAs (program derived addresses). Deterministic. Use findprogramaddress for off chain gen.
Errors? Logs in tx meta. solana logs or explorer.
Scale? Parallel execution. But CPI (cross program) limits if not careful.
Honestly, start small. Tweak the hello world. Add a deposit fn. Deploy. Iterate. You'll get it.
Solang. Solidity on Solana. solang compile to .so. Playground for no setup: solpg.io. Write, deploy to devnet sim in browser. Great for ETH devs.