From 6c74de7579a9ff410c8b4e443076b0e24d079e3e Mon Sep 17 00:00:00 2001 From: Evan <0xIchigo@protonmail.com> Date: Tue, 7 May 2024 12:39:33 -0400 Subject: [PATCH] Update Examples --- README.md | 12 +++++++++--- examples/get_asset_batch.rs | 17 +++++++++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index cf1425e..7fcd92d 100644 --- a/README.md +++ b/README.md @@ -32,9 +32,15 @@ async fn main() -> Result<(), HeliusError> { let api_key: &str = "YOUR_API_KEY"; let cluster: Cluster = Cluster::MainnetBeta; - let config: Config = Config::new(api_key, cluster)?; + let config: Arc = Arc::new(Config::new(api_key, cluster)?); let client: Client = Client::new(); - let rpc_client: RpcClient = RpcClient::new(Arc::new(client), Arc::new(config))?; + let rpc_client: Arc = Arc::new(RpcClient::new(Arc::new(client.clone()), Arc::clone(&config)).unwrap()); + + let helius: Helius = Helius { + config, + client, + rpc_client, + }; let request: GetAssetRequest = GetAssetRequest { id: "F9Lw3ki3hJ7PF9HQXsBzoY8GyE6sPoEZZdXJBsTTD2rk".to_string(), @@ -46,7 +52,7 @@ async fn main() -> Result<(), HeliusError> { }), }; - let response: Result, HeliusError> = rpc_client.get_asset(request).await; + let response: Result, HeliusError> = helius.rpc().get_asset(request).await; match response { Ok(Some(asset)) => { diff --git a/examples/get_asset_batch.rs b/examples/get_asset_batch.rs index f8e2337..56f2013 100644 --- a/examples/get_asset_batch.rs +++ b/examples/get_asset_batch.rs @@ -2,6 +2,9 @@ use helius_sdk::config::Config; use helius_sdk::error::HeliusError; use helius_sdk::rpc_client::RpcClient; use helius_sdk::types::{Asset, Cluster, GetAssetBatch, GetAssetOptions}; +use helius_sdk::Helius; + +use reqwest::Client; use std::sync::Arc; #[tokio::main] @@ -9,9 +12,15 @@ async fn main() -> Result<(), HeliusError> { let api_key: &str = "your_api_key"; let cluster: Cluster = Cluster::MainnetBeta; - let config: Config = Config::new(api_key, cluster)?; - let client: reqwest::Client = reqwest::Client::new(); - let rpc_client: RpcClient = RpcClient::new(Arc::new(client), Arc::new(config))?; + let config: Arc = Arc::new(Config::new(api_key, cluster)?); + let client: Client = Client::new(); + let rpc_client: Arc = Arc::new(RpcClient::new(Arc::new(client.clone()), Arc::clone(&config)).unwrap()); + + let helius: Helius = Helius { + config, + client, + rpc_client, + }; let request: GetAssetBatch = GetAssetBatch { ids: vec![ @@ -24,7 +33,7 @@ async fn main() -> Result<(), HeliusError> { }), }; - let response: Result>, HeliusError> = rpc_client.get_asset_batch(request).await; + let response: Result>, HeliusError> = helius.rpc().get_asset_batch(request).await; println!("Assets: {:?}", response); Ok(())