A clean, ergonomic Rust client for NEAR Protocol.
near-kit provides a fluent API for interacting with NEAR Protocol, with a focus on developer experience and type safety.
Quick Start
use *;
async
Design Principles
- Single entry point: Everything hangs off the [
Near] client - Configure once: Network and signer set at client creation
- Type-safe but ergonomic: Accept
"5 NEAR"strings while maintaining type safety - Explicit units: No ambiguous amounts - must specify
NEAR,yocto,Tgas, etc. - Progressive disclosure: Simple things are simple, advanced options available when needed
Core Types
- [
AccountId] - Validated NEAR account identifier - [
NearToken] - NEAR token amount with yoctoNEAR precision - [
Gas] - Gas units for transactions - [
PublicKey], [SecretKey] - Cryptographic keys - [
CryptoHash] - 32-byte SHA-256 hash
String Parsing
Many types support parsing from human-readable strings:
use ;
let amount: NearToken = "5 NEAR".parse.unwrap;
let gas: Gas = "30 Tgas".parse.unwrap;
let account: AccountId = "alice.testnet".parse.unwrap;
Typed Contract Interfaces
Use the #[near_kit::contract] macro to create type-safe contract clients:
use near_kit::*;
use serde::Serialize;
#[near_kit::contract]
pub trait Counter {
fn get_count(&self) -> u64;
#[call]
fn increment(&mut self);
}
let counter = near.contract::<Counter>("counter.testnet");
let count = counter.get_count().await?;
counter.increment().await?;