Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(webhook): Add Webhook Examples #34

Merged
merged 11 commits into from
May 29, 2024
18 changes: 18 additions & 0 deletions examples/append_address_to_webhook.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use helius::error::Result;
use helius::types::{Cluster, Webhook};
use helius::Helius;

#[tokio::main]
async fn main() -> Result<()> {
let api_key: &str = "your_api_key";
let cluster: Cluster = Cluster::MainnetBeta;

let helius: Helius = Helius::new(api_key, cluster).unwrap();

let webhook_id = "your_webhook_id";
let new_addresses = ["your_address1".to_string(), "your_address2".to_string()];
let response: Result<Webhook> = helius.append_addresses_to_webhook(webhook_id, &new_addresses).await;
println!("Addresses appended {:?}", response);

Ok(())
}
28 changes: 28 additions & 0 deletions examples/create_webhook.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use helius::error::Result;
use helius::types::{Cluster, Webhook, WebhookType};
use helius::{
types::{CreateWebhookRequest, TransactionType},
Helius,
};

#[tokio::main]
async fn main() -> Result<()> {
let api_key: &str = "your_api_key";
let cluster: Cluster = Cluster::MainnetBeta;

let helius: Helius = Helius::new(api_key, cluster).unwrap();

let request = CreateWebhookRequest {
webhook_url: "your_webhook".to_string(),
transaction_types: vec![TransactionType::Any],
account_addresses: vec!["your_addresses".to_string()],
webhook_type: WebhookType::Enhanced,
auth_header: None,
txn_status: Default::default(),
encoding: Default::default(),
};

let response: Result<Webhook> = helius.create_webhook(request).await;
println!("Webhook created {:?}", response);
Ok(())
}
17 changes: 17 additions & 0 deletions examples/delete_webhook.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use helius::error::Result;
use helius::types::Cluster;
use helius::Helius;

#[tokio::main]
async fn main() -> Result<()> {
let api_key: &str = "your_api_key";
let cluster: Cluster = Cluster::MainnetBeta;

let helius: Helius = Helius::new(api_key, cluster).unwrap();

let webhook_id = "your_webhook_id";

let response: Result<()> = helius.delete_webhook(webhook_id).await;
println!("Webhook deleted {:?}", response);
Ok(())
}
25 changes: 25 additions & 0 deletions examples/edit_webhook.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use helius::error::Result;
use helius::types::{Cluster, EditWebhookRequest, TransactionType, Webhook, WebhookType};
use helius::Helius;

#[tokio::main]
async fn main() -> Result<()> {
let api_key: &str = "your_api_key";
let cluster: Cluster = Cluster::MainnetBeta;

let helius: Helius = Helius::new(api_key, cluster).unwrap();
let request = EditWebhookRequest {
webhook_id: "your_webhook_id".to_string(),
webhook_url: "your_webhook".to_string(),
transaction_types: vec![TransactionType::Any],
account_addresses: vec!["your_addresses".to_string()],
webhook_type: WebhookType::Enhanced,
auth_header: None,
txn_status: Default::default(),
encoding: Default::default(),
};

let response: Result<Webhook> = helius.edit_webhook(request).await;
println!("Webhook edited {:?}", response);
Ok(())
}
15 changes: 15 additions & 0 deletions examples/get_all_webhooks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use helius::error::Result;
use helius::types::{Cluster, Webhook};
use helius::Helius;

#[tokio::main]
async fn main() -> Result<()> {
let api_key: &str = "your_api_key";
let cluster: Cluster = Cluster::MainnetBeta;

let helius: Helius = Helius::new(api_key, cluster).unwrap();

let response: Result<Vec<Webhook>> = helius.get_all_webhooks().await;
println!("Webhooks {:?}", response);
Ok(())
}
17 changes: 17 additions & 0 deletions examples/get_webhook_by_id.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use helius::error::Result;
use helius::types::{Cluster, Webhook};
use helius::Helius;

#[tokio::main]
async fn main() -> Result<()> {
let api_key: &str = "your_api_key";
let cluster: Cluster = Cluster::MainnetBeta;

let helius: Helius = Helius::new(api_key, cluster).unwrap();

let webhook_id = "your_webhook_id";
let response: Result<Webhook> = helius.get_webhook_by_id(webhook_id).await;
println!("Webhook {:?}", response);

Ok(())
}
20 changes: 20 additions & 0 deletions examples/remove_address_from_webhook.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use helius::error::Result;
use helius::types::{Cluster, Webhook};
use helius::Helius;

#[tokio::main]
async fn main() -> Result<()> {
let api_key: &str = "your_api_key";
let cluster: Cluster = Cluster::MainnetBeta;

let helius: Helius = Helius::new(api_key, cluster).unwrap();

let webhook_id = "your_webhook_id";
let addresses_to_remove = ["your_address1".to_string(), "your_address2".to_string()];
let response: Result<Webhook> = helius
.remove_addresses_from_webhook(webhook_id, &addresses_to_remove)
.await;
println!("Addresses removed {:?}", response);

Ok(())
}
Loading