Near Learn

Think in receipts · Advanced

Async & cross-contract patterns

On the EVM a transaction is one synchronous, atomic call stack. On NEAR it is a tree of receipts: each one runs on its own shard, commits on its own, and talks to the others only through promises and data receipts that arrive blocks later. Most surprising NEAR bugs, from lost refunds to double spends, come from code written as if the old model still applied.

This module builds the asynchronous model from the ground up. It starts with how a transaction turns into receipts and what a Promise really is, then works through callbacks, joins, batches and gas budgets for whole call trees. The later lessons turn that into designs that survive failure: pending states, idempotent callbacks, compensating actions, and the ordering guarantees you can and cannot rely on.

It finishes with yield/resume (NEP-519), which lets a contract pause until an off-chain worker answers, and with sandbox tests that make every failure branch run before mainnet does. All code is near-sdk 5.x Rust; where Solidity has an analog it is shown alongside.

10 lessons~125 min30 quiz questionsFree · no sign-up

What you’ll learn

  • Trace a transaction through its receipts, blocks, outcomes and refunds
  • Choose between returning, detaching and chaining a Promise, and know what the caller sees
  • Read callback results safely with #[callback_result] and bounded promise_result_checked
  • Fan out with Promise::and and handle partial failure without paying twice
  • Use atomic batch actions where they fit and chains where they must
  • Budget gas for a whole call tree and always reserve enough for the rollback path
  • Model async operations as state machines with ids, pending states and recovery paths
  • Build request/response flows with yield/resume and test every branch in a sandbox

Lessons