Expand description
A Rust library for interacting with the NEAR Protocol blockchain
This crate provides a high-level API for interacting with NEAR Protocol, including:
- Account management and creation
- Contract deployment and interaction with it
- Token operations (
NEAR
,FT
,NFT
) - Storage management
- Staking operations
- Custom transaction building and signing
- Querying the chain data
- Several ways to sign the transaction
- Account nonce caching and access-key pooling mechanisms to speed up the transaction processing.
- Support for backup RPC endpoints
ยงExample
In this example, we use Bob account with a predefined seed phrase to create Alice account and pre-fund it with 1 NEAR
.
use near_api::{*, signer::generate_secret_key};
use std::str::FromStr;
// Initialize network configuration
let bob = AccountId::from_str("bob.testnet")?;
let bob_seed_phrase = "lucky barrel fall come bottom can rib join rough around subway cloth ";
// Fetch NEAR balance
let _bob_balance = Tokens::account(bob.clone())
.near_balance()
.fetch_from_testnet()
.await?;
// Create an account instance
let signer = Signer::new(Signer::from_seed_phrase(bob_seed_phrase, None)?)?;
let alice_secret_key = generate_secret_key()?;
Account::create_account(AccountId::from_str("alice.testnet")?)
.fund_myself(bob.clone(), NearToken::from_near(1))
.public_key(alice_secret_key.public_key())?
.with_signer(signer)
.send_to_testnet()
.await?;
ยงFeatures
ledger
: Enables hardware wallet supportkeystore
: Enables system keychain integrationworkspaces
: Enables integration with near-workspaces for testing
Re-exportsยง
pub use crate::signer::Signer;
pub use crate::signer::SignerTrait;
pub use crate::types::reference::EpochReference;
pub use crate::types::reference::Reference;
pub use crate::types::tokens::FTBalance;
pub use crate::types::tokens::USDT_BALANCE;
pub use crate::types::tokens::W_NEAR_BALANCE;
pub use crate::types::Data;
pub use near_primitives;
Modulesยง
- account ๐
- advanced
- chain ๐
- common ๐
- config ๐
- contract ๐
- errors
- signer
- Transaction signing functionality for NEAR Protocol
- stake ๐
- storage ๐
- tokens ๐
- transactions ๐
- types
Structsยง
- Account
- Account management related interactions with the NEAR Protocol
- Account
Id - NEAR Account Identifier.
- Chain
- Chain-related interactions with the NEAR Protocol
- Contract
- Contract-related interactions with the NEAR Protocol
- Delegation
- A wrapper struct that simplifies interactions with the Staking Pool standard on behalf of the account.
- NearGas
- Near
Token - Network
Config - Configuration for a NEAR network including RPC endpoints and network-specific settings.
- RPCEndpoint
- Configuration for a NEAR RPC endpoint with retry and backoff settings.
- Staking
- Staking-related interactions with the NEAR Protocol and the staking pools.
- Storage
Deposit - A wrapper struct that simplifies interactions with the Storage Management standard
- Tokens
- A wrapper struct that simplifies interactions with NEAR, FT, NFT
- Transaction
- Transaction related functionality.
Enumsยง
- Retry
Method - Specifies the retry strategy for RPC endpoint requests.