Expand description
Proc macros for near-kit typed contract interfaces.
This crate provides the #[near_kit::contract] attribute macro for defining
type-safe contract interfaces.
§Example
ⓘ
use near_kit::*;
use serde::Serialize;
#[near_kit::contract]
pub trait Counter {
fn get_count(&self) -> u64;
#[call]
fn increment(&mut self);
#[call]
fn add(&mut self, args: AddArgs);
}
#[derive(Serialize)]
pub struct AddArgs {
pub value: u64,
}§Per-Method Format Override
You can override the serialization format for individual methods:
ⓘ
#[near_kit::contract] // Default: JSON
pub trait MixedContract {
fn get_json_data(&self) -> JsonData; // Uses JSON (default)
#[borsh] // Override: use Borsh for this method
fn get_binary_state(&self) -> BinaryState;
#[call]
#[borsh] // Override: use Borsh for this call
fn set_binary_state(&mut self, args: BinaryArgs);
}