near-api 0.7.0

Rust library to interact with NEAR Protocol via RPC API
Documentation

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;

# async fn example() -> Result<(), Box<dyn std::error::Error>> {
// 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?;
# Ok(())
# }

Features

  • ledger: Enables hardware wallet support
  • keystore: Enables system keychain integration
  • workspaces: Enables integration with near-workspaces for testing