Skip to content

Commit

Permalink
Merge pull request #3 from helius-labs/dev
Browse files Browse the repository at this point in the history
[Merge] Dev -> Main
  • Loading branch information
0xIchigo authored May 7, 2024
2 parents 4042a48 + a9e837a commit 8aa336c
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 8 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/publish_crate.yml
Original file line number Diff line number Diff line change
@@ -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 }}
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Config> = 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<RpcClient> = 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(),
Expand All @@ -46,7 +52,7 @@ async fn main() -> Result<(), HeliusError> {
}),
};

let response: Result<Option<GetAssetResponseForAsset>, HeliusError> = rpc_client.get_asset(request).await;
let response: Result<Option<GetAssetResponseForAsset>, HeliusError> = helius.rpc().get_asset(request).await;

match response {
Ok(Some(asset)) => {
Expand All @@ -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
Expand Down
17 changes: 13 additions & 4 deletions examples/get_asset_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,25 @@ 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]
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<Config> = Arc::new(Config::new(api_key, cluster)?);
let client: Client = Client::new();
let rpc_client: Arc<RpcClient> = 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![
Expand All @@ -24,7 +33,7 @@ async fn main() -> Result<(), HeliusError> {
}),
};

let response: Result<Vec<Option<Asset>>, HeliusError> = rpc_client.get_asset_batch(request).await;
let response: Result<Vec<Option<Asset>>, HeliusError> = helius.rpc().get_asset_batch(request).await;
println!("Assets: {:?}", response);

Ok(())
Expand Down
31 changes: 31 additions & 0 deletions examples/get_latest_blockhash.rs
Original file line number Diff line number Diff line change
@@ -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<Config> = Arc::new(Config::new(api_key, cluster)?);
let client: Client = Client::new();
let rpc_client: Arc<RpcClient> = Arc::new(RpcClient::new(Arc::new(client.clone()), Arc::clone(&config)).unwrap());

let helius: Helius = Helius {
config,
client,
rpc_client,
};

let result: Result<Hash, ClientError> = helius.connection().get_latest_blockhash();
println!("{:?}", result);

Ok(())
}

0 comments on commit 8aa336c

Please sign in to comment.