Crate near_api

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 near_api_types as types;

Modulesยง

account ๐Ÿ”’
advanced
chain ๐Ÿ”’
common ๐Ÿ”’
config ๐Ÿ”’
contract ๐Ÿ”’
errors
signer
Transaction signing functionality for NEAR Protocol
stake ๐Ÿ”’
storage ๐Ÿ”’
tokens ๐Ÿ”’
transactions ๐Ÿ”’

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
CryptoHash
A type that represents a hash of the data.
Data
A wrapper around a generic query result that includes the block height and block hash at which the query was executed
Delegation
A wrapper struct that simplifies interactions with the Staking Pool standard on behalf of the account.
FTBalance
A helper type that represents the fungible token balance with a given precision.
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ยง

EpochReference
A reference to a specific epoch. This type is used to specify the epoch for some queries.
PublicKey
Public key container supporting different curves.
Reference
A reference to a specific block. This type is used to specify the block for most queries.
RetryMethod
Specifies the retry strategy for RPC endpoint requests.
SecretKey
Secret key container supporting different curves.

Constantsยง

USDT_BALANCE
Static instance of FTBalance for USDT token with correct decimals and symbol.
W_NEAR_BALANCE
Static instance of FTBalance for wNEAR token with correct decimals and symbol.