diff --git a/.github/workflows/publish_crate.yml b/.github/workflows/publish_crate.yml new file mode 100644 index 0000000..b883676 --- /dev/null +++ b/.github/workflows/publish_crate.yml @@ -0,0 +1,26 @@ +name: Publish Helius SDK Crate + +on: + workflow_dispatch: + +jobs: + manual-job: + runs-on: ubuntu-latest + steps: + - name: Check out repository code + uses: actions/checkout@v4 + + - name: Setup Rust environment + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + default: true + profile: minimal + + - name: Publish to crates.io + uses: actions-rs/cargo@v1 + with: + command: publish + args: --token ${{ secrets.CRATES_IO_TOKEN }} + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }} \ No newline at end of file diff --git a/README.md b/README.md index cf1425e..f3731a0 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)) => { @@ -59,7 +65,9 @@ async fn main() -> Result<(), HeliusError> { Ok(()) } ``` -More examples on how to use the SDK can be found in the [`examples`](https://github.com/helius-labs/helius-rust-sdk/tree/dev/examples) directory. +The `Helius` client has an embedded [Solana client](https://docs.rs/solana-client/latest/solana_client/rpc_client/struct.RpcClient.html) that can be accessed via `helius.connection().request_name()` where `request_name()` is a given [RPC method](https://docs.rs/solana-client/latest/solana_client/rpc_client/struct.RpcClient.html#implementations). A full list of all Solana RPC HTTP methods can be found [here](https://solana.com/docs/rpc/http). + +More examples of how to use the SDK can be found in the [`examples`](https://github.com/helius-labs/helius-rust-sdk/tree/dev/examples) directory. ## Error Handling ### Common Error Codes 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(()) diff --git a/examples/get_latest_blockhash.rs b/examples/get_latest_blockhash.rs new file mode 100644 index 0000000..1205ebb --- /dev/null +++ b/examples/get_latest_blockhash.rs @@ -0,0 +1,31 @@ +use helius_sdk::config::Config; +use helius_sdk::error::HeliusError; +use helius_sdk::rpc_client::RpcClient; +use helius_sdk::types::*; +use helius_sdk::Helius; + +use reqwest::Client; +use solana_client::client_error::ClientError; +use solana_sdk::hash::Hash; +use std::sync::Arc; + +#[tokio::main] +async fn main() -> Result<(), HeliusError> { + let api_key: &str = "your_api_key"; + let cluster: Cluster = Cluster::MainnetBeta; + + 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 result: Result = helius.connection().get_latest_blockhash(); + println!("{:?}", result); + + Ok(()) +}