Crate near_api

Source
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:

ยง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 support
  • keystore: Enables system keychain integration
  • workspaces: 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
AccountId
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
NearToken
NetworkConfig
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.
StorageDeposit
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ยง

RetryMethod
Specifies the retry strategy for RPC endpoint requests.