Repository navigation
Doc: Solidity VS Rust Syntax Comparison - #38
Conversation
PetarStoev02
left a comment
There was a problem hiding this comment.
Hey @Raad05, nice initiative — a Solidity vs Rust cheatsheet is a great addition and aligns with issue #33. The structure and formatting are solid. However, there are several technical inaccuracies on the Rust/Solana side that need to be fixed before we can merge.
🔴 Must Fix
-
"CRATES (Anchor) or ASDROP" in the Deployment Differences table is incorrect — These are not real terms in the Solana ecosystem. Solana programs are upgraded via the built-in BPF Loader Upgradeable using an upgrade authority. With Anchor it's
anchor upgrade. Replace with something like "Native upgrade authority (BPF Loader Upgradeable)". -
Rust examples inconsistently mix raw Solana and Anchor without labeling — The Functions section uses raw Solana (
program_id, accounts, instruction_data), then Error Handling switches to Anchor (ctx: Context<Transfer>,require!). Pick one consistently (Anchor is more common) or clearly label each example as "Native Solana" vs "Anchor". -
HashMapas equivalent to Soliditymappingis misleading — Solana programs don't useHashMapfor on-chain storage. The equivalent of a Solidity mapping is Program Derived Addresses (PDAs) — each "entry" is its own account derived from seeds. TheHashMapexample would only work in-memory during a single instruction, not as persistent storage. -
require!macro used in a raw Solana example — In the Functions section,require!(from.is_signer, ...)is shown in a raw Solana program.require!is Anchor-only and won't compile without it. For native Solana, use:if !from.is_signer { return Err(ProgramError::MissingRequiredSignature); }
-
try_borrow_mut_data()is misleading as a "balance" — The variables are namedfrom_balanceandto_balance, buttry_borrow_mut_data()returns raw bytes (&mut [u8]), not a balance. For SOL transfers, usetry_borrow_mut_lamports():**from.try_borrow_mut_lamports()? -= amount; **to.try_borrow_mut_lamports()? += amount;
🟡 Should Fix
- Typo: "Comparision" → "Comparison" — In both the PR title and commit message (the file heading is correct).
- Anchor test example is non-standard — The Rust
#[tokio::test]withanchor_client::Clientpattern shown is not how Anchor tests are typically written. Default Anchor tests use TypeScript with Mocha. Either show the standard TS test or use a modern Rust testing approach (LiteSVM/Mollusk). - "Annual rent" is outdated — Solana moved to rent-exempt-only (SIMD-84). Rent collection is disabled. It's a one-time refundable storage deposit, not an annual fee. Update the Storage Cost table accordingly.
- Link to issue #33 — This PR is part of the cheat sheets effort, should reference it.
- 2 resource URLs are outdated and redirect:
https://docs.solana.com/→ should behttps://solana.com/docshttps://spl.solana.com/token→ should behttps://www.solana-program.com/docs/token
- Resources are too generic — They all link to homepages. Consider linking to specific relevant pages like
solana.com/docs/core/accounts,anchor-lang.com/docs/features/errors,solana.com/docs/programs/deploying, etc.
🟢 Nice to Have
- SBPF (eBPF) — SBPF is a fork of eBPF, not eBPF itself. Consider "SBF (eBPF-derived)" to be more precise.
- Add a note at the top of the file clarifying whether Rust examples target Anchor or native Solana.
The Solidity side of the cheatsheet looks accurate and well-structured. Once the Rust/Solana side is corrected this will be a great resource 👍
Hey @PetarStoev02 , I have updated the cheat sheet. Waiting for your review! |
- Replace manual account mutation with token::transfer and token::approve CPIs via anchor_spl - Fix require! to use error codes instead of string literals - Fix load()/load_mut() to direct field access on Account types - Update quick reference table accordingly
PetarStoev02
left a comment
There was a problem hiding this comment.
Hey @Raad05, great job on the updates — you addressed almost everything from the first review. I pushed a small fixup commit for the remaining issues in the Common Operations section (require! string literals → error codes, load()/load_mut() → direct field access, and SPL token transfer → CPI pattern).
This is ready to merge now. Solid cheatsheet, thanks for the contribution! 🤝
Feel free to pick up another issue from the repo if you're interested — there's more cheatsheets and guides to work on.
What
Adds a new cheat sheet that compares Solidity and Rust smart contract syntax and patterns side by side.
Why
How
Checklist