Expand description
Core types for NEAR Protocol.
This module provides hand-rolled types based on NEAR RPC responses, designed for ergonomic use in client applications.
§Primary Types
| Type | Description |
|---|---|
AccountId | Validated NEAR account identifier |
NearToken | Token amount with yoctoNEAR (10⁻²⁴) precision |
Gas | Gas units for transactions |
PublicKey | Ed25519 or Secp256k1 public key |
SecretKey | Ed25519 or Secp256k1 secret key |
CryptoHash | 32-byte SHA-256 hash (blocks, transactions) |
§Amount Types
NearToken and Gas support both typed constructors and string parsing:
use near_kit::{NearToken, Gas};
// Typed constructors (compile-time safe, zero-cost)
let amount = NearToken::near(5);
let gas = Gas::tgas(30);
// String parsing (for runtime input)
let amount: NearToken = "5 NEAR".parse().unwrap();
let gas: Gas = "30 Tgas".parse().unwrap();§Block References
BlockReference specifies which block state to query:
BlockReference::Finality(Finality::Final)— Fully finalized (default)BlockReference::Finality(Finality::Optimistic)— Latest optimisticBlockReference::Height(12345)— Specific block heightBlockReference::Hash(hash)— Specific block hash
§RPC Response Types
Types for RPC responses include AccountView, BlockView,
FinalExecutionOutcome, and others.
Modules§
- nep413
- NEP-413: Off-chain message signing for authentication.
Structs§
- Access
Key - Access key attached to an account.
- Access
KeyDetails - Access key details (without block info, used in lists).
- Access
KeyInfo View - Single access key info in list.
- Access
KeyList View - Access key list from view_access_key_list RPC.
- Access
KeyView - Access key information from view_access_key RPC.
- Account
Balance - Simplified balance info.
- Account
Id - A NEAR account identifier.
- Account
View - Account information from view_account RPC.
- Action
Error - An error that occurred during action execution.
- Action
Receipt Data - Action receipt data.
- AddKey
Action - Add an access key.
- Bandwidth
Request - A single bandwidth request to a target shard.
- Bandwidth
Request Bitmap - Bitmap for bandwidth request values.
- Bandwidth
Requests V1 - Bandwidth requests data (V1).
- Block
Header Inner Lite View - Block header inner lite (for light client proofs).
- Block
Header View - Block header with full details.
- Block
View - Block information from block RPC.
- Chunk
Header View - Chunk header with full details.
- Congestion
Info View - Congestion information for a shard.
- Create
Account Action - Create a new account.
- Crypto
Hash - A 32-byte SHA-256 hash used for block hashes, transaction hashes, etc.
- Current
Epoch Validator Info - Current epoch validator information.
- Data
Receipt Data - Data receipt data.
- Data
Receiver View - Data receiver for output data in action receipts.
- Delegate
Action - Delegate action for meta-transactions.
- Delegate
Action View - View of a delegate action in RPC responses.
- Delete
Account Action - Delete the account.
- Delete
KeyAction - Delete an access key.
- Deploy
Contract Action - Deploy contract code.
- Deploy
Global Contract Action - Publish a contract to the global registry.
- Deterministic
Account State Init V1 - Version 1 of deterministic account state initialization.
- Deterministic
State Init Action - Deploy a contract with a deterministically derived account ID (NEP-616).
- Epoch
Validator Info - Epoch validator info from
validatorsRPC. - Execution
Metadata - Execution metadata with gas profiling.
- Execution
Outcome - Execution outcome details.
- Execution
Outcome With Id - Execution outcome with ID.
- Final
Execution Outcome - Final execution outcome from send_tx RPC.
- Final
Execution Outcome With Receipts - Final execution outcome with receipts (from EXPERIMENTAL_tx_status).
- Function
Call Action - Call a contract function.
- Function
Call Permission - Function call access key permission details.
- Gas
- Gas units for NEAR transactions.
- GasKey
Info - Gas key information.
- GasPrice
- Gas price response.
- GasProfile
Entry - Gas profile entry for detailed gas accounting.
- KeyPair
- A cryptographic key pair (secret key + public key).
- Light
Client Block Lite View - Light client block lite view.
- Light
Client Block View - Light client block view from
next_light_client_blockRPC. - Merkle
Path Item - Merkle path item for cryptographic proofs.
- Near
Token - A NEAR token amount with yoctoNEAR precision (10^-24 NEAR).
- Next
Epoch Validator Info - Next epoch validator information.
- Node
Version - Node version information.
- NonDelegate
Action - Non-delegate action (for use within DelegateAction).
- Public
Key - Ed25519 or Secp256k1 public key.
- Receipt
- Receipt from EXPERIMENTAL_tx_status.
- Secret
Key - Ed25519 or Secp256k1 secret key.
- Send
TxResponse - Response from
send_txRPC. - Send
TxWith Receipts Response - Response from
EXPERIMENTAL_tx_statusRPC. - Signature
- Cryptographic signature.
- Signed
Delegate Action - Signed delegate action.
- Signed
Transaction - A signed transaction ready to be sent.
- Slashed
Validator - Slashed validator from challenge results.
- Stake
Action - Stake NEAR for validation.
- State
Change With Cause View - State change with its cause (from
EXPERIMENTAL_changesRPC). - Status
Response - Node status response.
- Sync
Info - Sync information.
- Transaction
- An unsigned transaction.
- Transaction
View - Transaction view in outcome.
- Transfer
Action - Transfer NEAR tokens.
- Transfer
ToGas KeyAction - Transfer NEAR to a gas key.
- Trie
Split - Trie split information for resharding.
- UseGlobal
Contract Action - Deploy a contract from the global registry.
- Validator
Info - Validator information.
- Validator
Kickout View - Validator kickout information.
- Validator
Stake View V1 - Validator stake data.
- View
Function Result - View function result from call_function RPC.
- Withdraw
From GasKey Action - Withdraw NEAR from a gas key.
Enums§
- Access
KeyPermission - Access key permission.
- Access
KeyPermission View - Access key permission from RPC.
- Action
- A transaction action.
- Action
Error Kind - Specific kind of action error.
- Action
View - Action view in transaction.
- Actions
Validation Error - Error validating actions in a transaction or receipt.
- Bandwidth
Requests - Bandwidth requests for a chunk (versioned).
- Block
Reference - Reference to a specific block for RPC queries.
- Compilation
Error - Wasm compilation error.
- Delegate
Decode Error - Error decoding a signed delegate action.
- Deposit
Cost Failure Reason - Reason a deposit cost check failed on a gas key transaction.
- Deterministic
Account State Init - State initialization data for NEP-616 deterministic accounts.
- Execution
Status - Per-receipt execution status.
- Final
Execution Status - Overall transaction execution status.
- Finality
- Finality level for queries.
- Function
Call Error - An error during function call execution.
- Global
Contract Deploy Mode - Deploy mode for global contracts.
- Global
Contract Identifier - How a global contract is identified in the registry.
- Global
Contract Identifier View - Global contract identifier in RPC view responses.
- Host
Error - Error from a host function call.
- Invalid
Access KeyError - Error related to access key validation.
- Invalid
TxError - An error during transaction validation (before execution).
- KeyType
- Key type identifier.
- Merkle
Direction - Direction in merkle path.
- Method
Resolve Error - Error resolving a method in Wasm.
- Network
- The NEAR network the client is connected to.
- Prepare
Error - Error preparing a Wasm module.
- Receipt
Content - Receipt content - action, data, or global contract distribution.
- Receipt
Validation Error - Error validating a receipt.
- State
Change Cause View - Cause of a state change.
- State
Change Value View - State change value.
- Storage
Error - Internal storage error.
- Sync
Checkpoint - Sync checkpoint for block references.
- TxExecution
Error - Error returned by NEAR RPC when a transaction or receipt fails.
- TxExecution
Status - Transaction execution status for send_tx wait_until parameter.
- Validator
Kickout Reason - Reason a validator was kicked out.
- Validator
Stake View - Validator stake (versioned).
- Wasm
Trap - A trap during Wasm execution.
Constants§
- DEFAULT_
HD_ PATH - Default BIP-32 HD derivation path for NEAR keys. NEAR uses coin type 397 per SLIP-44.
- DEFAULT_
WORD_ COUNT - Default number of words in generated seed phrases.
- DELEGATE_
ACTION_ PREFIX - NEP-461 prefix for delegate actions (meta-transactions). Value: 2^30 + 366 = 1073742190
- STORAGE_
AMOUNT_ PER_ BYTE - Cost per byte of storage in yoctoNEAR.
Traits§
- IntoGas
- Trait for types that can be converted into Gas.
- Into
Near Token - Trait for types that can be converted into a NearToken.
Functions§
- generate_
seed_ phrase - Generate a random BIP-39 seed phrase.