Skip to content
by Unity Nodes
near-sdk (Rust)Stable

near-sdk (Rust) 5.1.0

near-sdk-v5.1.0github.com

Reduce your boilerpate and enable ABI support out of the box with the new #[near] macro-attribute.

Hightlights

Reduce your boilerpate and enable ABI support out of the box with the new #[near] macro-attribute.

BEFORE (still valid, not breaking changes or deprecation in this release): AFTER
use near_sdk::serde::{Deserialize, Serialize}
use near_sdk::borsh::{BorshDeserialize, BorshSerialize};
use near_sdk::schemars::JsonSchema;

#[derive(Deserialize, Serialize, JsonSchema, BorshDeserlialize, BorshSerialize)]
#[serde(crate = "near_sdk::serde")]
#[schemars(crate = "near_sdk::schemars")]
#[borsh(crate = "near_sdk::borsh")]
struct ...
use near_sdk::near;

#[near(serializers = [borsh, json])]
struct ...
use near_sdk::{near_bindgen, env};

#[near_bindgen]
#[derive(Default, BorshDeserialize, BorshSerialize)]
#[borsh(crate = "near_sdk::borsh")]
pub struct StatusMessage {
    records: HashMap<AccountId, String>,
}

#[near]
impl StatusMessage { ... }
use near_sdk::{near, env};

#[near(contract_state)]
#[derive(Default)]
pub struct StatusMessage {
    records: HashMap<AccountId, String>,
}

#[near]
impl StatusMessage { ... }

If you want to have an example, look no further, DevHub Contract is already migrated

Added

  • Finalize #[near] attribute-macro implementation with the support for custom parameters passing to serializer attributes #[near(serializers = [borsh(...)])] (#1158)
  • Introduce #[near] macro to further streamline contracts development reducing the boilerplate! (#1142)

Other

  • add typo checker in ci (#1159)