near_api/lib.rs
1//! A Rust library for interacting with the NEAR Protocol blockchain
2//!
3//! This crate provides a high-level API for interacting with NEAR Protocol, including:
4//! - [Account management and creation](Account)
5//! - [Contract deployment and interaction with it](Contract)
6//! - [Token operations](Tokens) ([`NEAR`](https://docs.near.org/concepts/basics/tokens), [`FT`](https://docs.near.org/build/primitives/ft), [`NFT`](https://docs.near.org/build/primitives/nft))
7//! - [Storage management](StorageDeposit)
8//! - [Staking operations](Staking)
9//! - [Custom transaction building and signing](Transaction)
10//! - [Querying the chain data](Chain)
11//! - [Several ways to sign the transaction](signer)
12//! - Account nonce caching and access-key pooling mechanisms to speed up the transaction processing.
13//! - Support for backup RPC endpoints
14//!
15//! # Example
16//! In this example, we use Bob account with a predefined seed phrase to create Alice account and pre-fund it with 1 `NEAR`.
17//! ```rust,no_run
18//! use near_api::{*, signer::generate_secret_key};
19//! use std::str::FromStr;
20//!
21//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
22//! // Initialize network configuration
23//! let bob = AccountId::from_str("bob.testnet")?;
24//! let bob_seed_phrase = "lucky barrel fall come bottom can rib join rough around subway cloth ";
25//!
26//! // Fetch NEAR balance
27//! let _bob_balance = Tokens::account(bob.clone())
28//! .near_balance()
29//! .fetch_from_testnet()
30//! .await?;
31//!
32//! // Create an account instance
33//! let signer = Signer::new(Signer::from_seed_phrase(bob_seed_phrase, None)?)?;
34//! let alice_secret_key = generate_secret_key()?;
35//! Account::create_account(AccountId::from_str("alice.testnet")?)
36//! .fund_myself(bob.clone(), NearToken::from_near(1))
37//! .public_key(alice_secret_key.public_key())?
38//! .with_signer(signer)
39//! .send_to_testnet()
40//! .await?;
41//! # Ok(())
42//! # }
43//! ```
44//!
45//! # Features
46//! - `ledger`: Enables hardware wallet support
47//! - `keystore`: Enables system keychain integration
48//! - `workspaces`: Enables integration with near-workspaces for testing
49
50mod account;
51mod chain;
52mod config;
53mod contract;
54mod stake;
55mod storage;
56mod tokens;
57mod transactions;
58// TODO: to be honest, there is almost nothing in this file
59// we should maybe integrate with them more tightly
60// for now, i comment it out
61// mod fastnear;
62
63mod common;
64
65pub mod errors;
66pub mod signer;
67pub mod types;
68
69pub use crate::{
70 account::Account,
71 chain::Chain,
72 config::{NetworkConfig, RPCEndpoint, RetryMethod},
73 contract::Contract,
74 signer::{Signer, SignerTrait},
75 stake::{Delegation, Staking},
76 storage::StorageDeposit,
77 tokens::Tokens,
78 transactions::Transaction,
79 types::{
80 reference::{EpochReference, Reference},
81 tokens::{FTBalance, USDT_BALANCE, W_NEAR_BALANCE},
82 Data,
83 },
84};
85
86pub mod advanced {
87 pub use crate::common::query::*;
88 pub use crate::common::send::*;
89}
90
91pub use near_primitives;
92
93pub use near_account_id::AccountId;
94pub use near_gas::NearGas;
95pub use near_token::NearToken;