Skip to content

Commit

Permalink
feat: Added a new example to view contract state (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
frol authored Aug 31, 2023
1 parent 517ba06 commit e0217b7
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions examples/contract_view_state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use near_jsonrpc_client::methods;
use near_jsonrpc_primitives::types::query::QueryResponseKind;
use near_primitives::types::{AccountId, BlockReference, Finality};
use near_primitives::views::QueryRequest;

mod utils;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();

let client = utils::select_network()?;

let contract_id: AccountId =
utils::input("Enter the contract whose state you want to inspect: ")?.parse()?;

let request = methods::query::RpcQueryRequest {
block_reference: BlockReference::Finality(Finality::Final),
request: QueryRequest::ViewState {
account_id: contract_id.clone(),
prefix: near_primitives::types::StoreKey::from(Vec::new()),
include_proof: false,
},
};

let response = client.call(request).await?;

if let QueryResponseKind::ViewState(result) = response.kind {
println!("{:#?}", result);
}

Ok(())
}

0 comments on commit e0217b7

Please sign in to comment.