Function view_state

Source
pub async fn view_state(
    provider: Arc<dyn Provider>,
    contract_id: AccountId,
    prefix: Option<String>,
) -> Result<ViewStateResult, Box<dyn Error>>
Expand description

Queries the state of a contract on the NEAR blockchain using a key prefix.

This method allows you to inspect the storage of a contract, filtered by a key prefix.

§Arguments

  • provider - The provider through which to query the blockchain.
  • contract_id - The account ID of the contract whose state is being queried.
  • prefix - An optional key prefix to filter the state by. If None, all state is returned.

§Returns

A Result containing the contract’s state filtered by the specified prefix, or an error if the query fails.

Examples found in repository?
examples/view_state.rs (line 14)
7async fn main() -> Result<(), Box<dyn std::error::Error>> {
8    env_logger::init();
9
10    let provider = Arc::new(JsonRpcProvider::new("https://rpc.testnet.near.org"));
11
12    let contract_id: AccountId = "contract.near-api-rs.testnet".parse::<AccountId>()?;
13
14    let result = view_state(provider, contract_id, None).await;
15    println!("response: {:#?}", result);
16
17    Ok(())
18}