Near Learn

Start here · Beginner

NEAR by Example

Learn to write NEAR smart contracts the way you already think — in Solidity. Every concept is shown side by side: the Solidity you know on the left, the NEAR equivalent (Rust) on the right.

Compact and complete: short, real examples you can read top to bottom, each with a note on what changes when you come from the EVM, and a three-question check at the end.

27 lessons~105 min81 quiz questionsFree · no sign-up

What you’ll learn

  • Write, initialise and deploy a NEAR contract in Rust
  • Model state with near-sdk collections and pay for storage
  • Handle accounts, access keys, deposits and transfers
  • Make asynchronous cross-contract calls with callbacks
  • Implement the NEAR token standards (FT, NFT, multi-token)
  • Emit events, manage ownership, upgrade and test contracts

Lessons

3. Functions & calls

  1. Functions: view, mutating & payableReads vs writes are the &self vs &mut self receiver. Accepting NEAR needs #[payable]. msg.sender and msg.value become env:: calls.
  2. Initialization (constructors)When default state is not enough, mark a method #[init]. It runs once, takes arguments, and returns the starting state — the constructor.
  3. Errors: assert, require & panicGuard clauses roll the whole call back and refund unused gas. require! and env::panic_str are your revert.
  4. Access control (modifiers)Rust has no modifier keyword. You write a small guard method and call it at the top of each protected method — same effect, plain code.
  5. GasNEAR meters gas too, but measured in gas units (Tgas), paid by the caller, and attached explicitly to cross-contract calls.
  6. View vs change callsReads are free RPC queries with no signer and no gas; writes are signed transactions. Calling a read as a transaction costs gas and changes nothing — a classic first surprise.