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-sysand 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/**andnear-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 bynear-sdk-env/src/**. - Standard token implementations preserve interoperable public interfaces through
near-contract-standards/src/**.
Routing table
- near-sdk/Cargo.toml,
near-sdk/src/**-> docs/contract-sdk-authoring.md - near-sdk-macros/Cargo.toml,
near-sdk-macros/src/**-> docs/contract-interface-macros.md - near-sdk/…/promise*.rs,
near-sdk/src/types/**, near-sdk-env/…/promise*.rs -> docs/promises-and-cross-contract-calls.md near-sdk/src/environment/**, near-sdk-env/Cargo.toml,near-sdk-env/src/**-> docs/runtime-environment-and-context.mdnear-sdk/src/private/**, near-sdk/…/state*.rs,near-sdk/src/utils/**-> docs/contract-state-and-initialization.mdnear-sdk/src/collections/**,near-sdk/src/store/**-> docs/persistent-collections-and-store.mdnear-sdk/src/json_types/**, near-sdk/…/event*.rs, near-sdk-core/Cargo.toml,near-sdk-core/src/**-> docs/events-json-and-contract-types.md- near-contract-standards/Cargo.toml,
near-contract-standards/src/**-> docs/contract-standards.md near-contract-standards/src/fungible_token/**-> docs/fungible-token-standard.mdnear-contract-standards/src/non_fungible_token/**-> docs/non-fungible-token-standard.mdnear-contract-standards/src/storage_management/**,near-contract-standards/src/upgrade/**-> docs/storage-management-and-upgrades.md- near-global-contracts/Cargo.toml,
near-global-contracts/src/**,near-sdk/src/global_contracts/**-> docs/global-contracts.md near-global-contracts/src/**, near-sdk/…/state_init*.rs -> docs/global-contract-identifiers-and-state-init.md- near-crypto-hash/Cargo.toml,
near-crypto-hash/src/**-> docs/crypto-hash-utilities.md - near-digest/Cargo.toml,
near-digest/src/**, near-sys/Cargo.toml,near-sys/src/**-> docs/crypto-and-host-interfaces.md - near-digest/Cargo.toml,
near-digest/src/**-> docs/digest-algorithms.md - near-sys/Cargo.toml,
near-sys/src/**-> docs/near-host-abi-bindings.md near-sdk/src/types/**, near-sdk/…/env.rs,near-sdk/src/collections/**-> docs/bls12381-cryptography.mdcontract-builder/**,examples/**,scripts/**,.github/workflows/**-> docs/contract-build-and-example-workflows.md