NearClient

Struct NearClient 

Source
pub struct NearClient { /* private fields */ }
Expand description

Near RPC client

Implementations§

Source§

impl NearClient

Source

pub fn new(url: Url) -> Result<Self, Error>

Creates a new client

§Arguments
  • url - A RPC Endpoint Url
Source

pub async fn block(&self, finality: Finality) -> Result<CryptoHash, Error>

Queries network and returns block for given height or hash

Source

pub async fn view<'a, T: DeserializeOwned>( &'a self, contract_id: &'a AccountId, finality: Finality, method: &'static str, args: Option<Value>, ) -> Result<ViewOutput<T>, Error>

Allows you to call a contract method as a view function.

Arguments

  • contract_id - The AccountId where smart contract is located
  • finality - Finality
  • method - Function that is declared in a smart contract
  • args - Function arguments, could be empty
Source

pub async fn view_access_key( &self, account_id: &AccountId, public_key: &Ed25519PublicKey, finality: Finality, ) -> Result<AccessKeyView, Error>

Returns information about a single access key for given account

Arguments

Source

pub async fn view_access_key_list( &self, account_id: &AccountId, finality: Finality, ) -> Result<AccessKeyListView, Error>

Returns list of all access keys for the given account

Arguments

  • account_id - The user AccountId in a Near network
Source

pub async fn view_contract_state( &self, account_id: &AccountId, ) -> Result<ViewStateResult, Error>

Returns information regarding contract state in a key-value sequence representation

Arguments

  • account_id - The contract AccountId in a Near network
Source

pub async fn network_status(&self) -> Result<StatusResponse, Error>

Returns general status of a given node (sync status, nearcore node version, protocol version, etc), and the current set of validators.

Source

pub async fn view_transaction<'a>( &'a self, transaction_id: &'a CryptoHash, signer: &'a Signer, ) -> Result<Output, Error>

Queries status of a transaction by hash, returning the final transaction result and details of all receipts.

Arguments

Return

If a transaction still processing will be returned an error Error::ViewTransaction, in this case can try to execute view_transaction one more time, or a several times. If an error differs from Error::ViewTransaction that something goes totally wrong and you should stop to try executing view_transaction with the same arguments/signer

Source

pub async fn view_account( &self, account_id: &AccountId, ) -> Result<Account, Error>

Returns basic account information.

§Arguments
  • account_id - The account ID AccountId for which to retrieve information.
§Returns

Returns a struct Account containing basic information about the specified Near account.

Source

pub fn add_access_key<'a>( &'a self, signer: &'a Signer, account_id: &'a AccountId, new_account_pk: Ed25519PublicKey, permission: AccessKeyPermission, ) -> FunctionCall<'_>

Creates new access key on the specified account

Arguments

  • signer - Transaction Signer
  • account_id - The user AccountId in a Near network
  • new_account_pk - The new Ed25519PublicKey
  • permission - Granted permissions level for the new access key
Source

pub fn delete_access_key<'a>( &'a self, signer: &'a Signer, account_id: &'a AccountId, public_key: Ed25519PublicKey, ) -> FunctionCall<'_>

Deletes an access key on the specified account

Arguments

Source

pub fn function_call<'a>( &'a self, signer: &'a Signer, contract_id: &'a AccountId, method: &'static str, ) -> FunctionCallBuilder<'_>

Execute a transaction with a function call to the smart contract

Arguments

  • signer - Transaction Signer
  • contract_id - The AccountId where smart contract is located
  • method - Function that is declared in a smart contract (Arguments fir function call provided later in a [FunctionCallBuilder])
Source

pub fn deploy_contract<'a>( &'a self, signer: &'a Signer, contract_id: &'a AccountId, wasm: Vec<u8>, ) -> FunctionCall<'_>

Deploys contract code to the chain

§Arguments
  • signer - Transaction Signer
  • contract_id - The AccountId where smart contract is located
  • wasm - Actually a compiled code
Source

pub fn create_account<'a>( &'a self, signer: &'a Signer, new_account_id: &'a AccountId, new_account_pk: Ed25519PublicKey, amount: Balance, ) -> FunctionCall<'_>

Creates account

§Arguments
  • signer - Transaction Signer
  • new_account_id - The new AccountId
  • new_account_pk - The new Ed25519PublicKey
  • amount - Initial balance of that account, could be zero
Source

pub fn delete_account<'a>( &'a self, signer: &'a Signer, account_id: &'a AccountId, beneficiary_acc_id: &'a AccountId, ) -> FunctionCall<'_>

Deletes account

§Arguments
  • signer - Transaction Signer
  • account_id - The AccountId that we own and want to delete
  • beneficiary_acc_id - Where to return a founds from the deleted account
Source

pub fn send<'a>( &'a self, signer: &'a Signer, receiver_id: &'a AccountId, deposit: Balance, ) -> FunctionCall<'_>

Sends Near tokens from one account to another.

§Arguments
  • signer - The account ID of the sender and transaction Signer
  • receiver_id - The account ID of the receiver.
  • deposit - The amount of Near tokens to send.
§Errors

Possible error conditions include insufficient funds, invalid account IDs, or other issues preventing the successful execution of the transaction.

Trait Implementations§

Source§

impl Clone for NearClient

Source§

fn clone(&self) -> NearClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,