-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added a new example to view contract state (#129)
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |