Introducing a new way to review your PRs.

Read the announcement

near / near-sdk-rs

Rust library for writing NEAR smart contracts

View on GitHub

20 documents · Updated Nov 20, 2026

overview

Knowledge Base updated: 2026-11-19

near-sdk-rs knowledge base

Orientation

near-sdk-rs is the Rust SDK and supporting crate workspace for writing NEAR smart contracts. Its public SDK layer combines procedural macros, runtime environment access, persistent state, serialization, asynchronous promises, and contract-facing types.

Reusable NEAR standards provide interoperable fungible-token, non-fungible-token, storage-management, metadata, event, and upgrade components. Separate global-contract support covers shared contract code and universal state initialization.

Contract state ultimately lives in NEAR runtime storage. The SDK environment and near-sys bindings bridge contract code to host functions, while cryptographic utility crates provide hashing, digest, signature, and ABI-facing primitives.

flowchart TD
  Contract[Contract implementation] --> SDK[near-sdk]
  SDK --> Macros[near-sdk-macros]
  SDK --> Env[near-sdk-env]
  SDK --> Core[near-sdk-core]
  SDK --> Store[Persistent collections and store]
  SDK --> Promises[Promises and cross-contract calls]
  Macros --> Entrypoints[Generated contract entrypoints]
  Env --> Sys[near-sys host ABI bindings]
  Sys --> Runtime[NEAR runtime host functions]
  Store --> RuntimeStorage[NEAR runtime storage]
  Promises --> Runtime
  Standards[near-contract-standards] --> SDK
  Global[near-global-contracts] --> SDK
  Digest[near-digest] --> SDK
  Crypto[Crypto hash and BLS primitives] --> SDK

Glossary

  • near_bindgen: SDK annotation machinery that exposes Rust contract methods through NEAR-compatible entrypoints.
  • Promise: A scheduled asynchronous NEAR action, optionally chained with callbacks and result inspection.
  • Global contract: Shared contract code identified and deployed for use across accounts, with specialized initialization lifecycle support.
  • Universal state initialization: Global-contract workflow support for establishing a contract instance’s initial state.
  • Host ABI: The low-level NEAR runtime function interface exposed by near-sys and wrapped by environment APIs.

Invariants

  • Contract-facing methods must cross an SDK-generated serialization and entrypoint boundary; macro generation is implemented under near-sdk-macros/**.
  • Persistent contract data is mediated through runtime storage APIs rather than process-local durability; see near-sdk/src/store/** and near-sdk-env/src/**.
  • Cross-contract actions are asynchronous promises whose callbacks observe runtime-provided results; see near-sdk/…/promise.rs and near-sdk-env/src/**.
  • Low-level host calls remain below the safer environment layer; near-sys/src/** is wrapped by near-sdk-env/src/**.
  • Standard token implementations preserve interoperable public interfaces through near-contract-standards/src/**.

Routing table