pub struct ViewCall<T> { /* private fields */ }Expand description
Query builder for calling view functions on contracts.
§Example
let near = Near::testnet().build();
// Simple view call without args
let count: u64 = near.view("counter.testnet", "get_count").await?;
// View call with args
let messages: Vec<String> = near.view("guestbook.testnet", "get_messages")
.args(serde_json::json!({ "limit": 10 }))
.await?;
// Query at specific block
let old_count: u64 = near.view("counter.testnet", "get_count")
.at_block(100_000_000)
.await?;Implementations§
Source§impl<T> ViewCall<T>
impl<T> ViewCall<T>
Sourcepub fn args<A: Serialize>(self, args: A) -> Self
pub fn args<A: Serialize>(self, args: A) -> Self
Set JSON arguments for the view call.
The arguments will be serialized to JSON.
Sourcepub fn args_borsh<A: BorshSerialize>(self, args: A) -> Self
pub fn args_borsh<A: BorshSerialize>(self, args: A) -> Self
Set Borsh-encoded arguments.
Sourcepub fn at_block_hash(self, hash: CryptoHash) -> Self
pub fn at_block_hash(self, hash: CryptoHash) -> Self
Query at a specific block hash.
Sourcepub fn borsh(self) -> ViewCallBorsh<T>
pub fn borsh(self) -> ViewCallBorsh<T>
Switch to Borsh deserialization for the response.
By default, ViewCall deserializes responses as JSON. Call this method
to deserialize as Borsh instead. This is useful for contracts that return
Borsh-encoded data.
§Example
use near_kit::*;
use borsh::BorshDeserialize;
#[derive(BorshDeserialize)]
struct ContractState { count: u64 }
async fn example() -> Result<(), near_kit::Error> {
let near = Near::testnet().build();
// Borsh response deserialization
let state: ContractState = near.view("contract.testnet", "get_state")
.borsh()
.await?;
Ok(())
}Trait Implementations§
Source§impl<T: DeserializeOwned + Send + 'static> IntoFuture for ViewCall<T>
impl<T: DeserializeOwned + Send + 'static> IntoFuture for ViewCall<T>
Source§type IntoFuture = Pin<Box<dyn Future<Output = <ViewCall<T> as IntoFuture>::Output> + Send>>
type IntoFuture = Pin<Box<dyn Future<Output = <ViewCall<T> as IntoFuture>::Output> + Send>>
Which kind of future are we turning this into?
Source§fn into_future(self) -> Self::IntoFuture
fn into_future(self) -> Self::IntoFuture
Creates a future from a value. Read more
Auto Trait Implementations§
impl<T> Freeze for ViewCall<T>
impl<T> !RefUnwindSafe for ViewCall<T>
impl<T> Send for ViewCall<T>where
T: Send,
impl<T> Sync for ViewCall<T>where
T: Sync,
impl<T> Unpin for ViewCall<T>where
T: Unpin,
impl<T> UnsafeUnpin for ViewCall<T>
impl<T> !UnwindSafe for ViewCall<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more