solagent_plugin_helius/
create_webhook.rs1use serde::{Deserialize, Serialize};
16use solagent_core::SolanaAgentKit;
17
18#[derive(Deserialize, Serialize)]
19pub struct HeliusWebhookResponse {
20 pub webhook_url: String,
21 pub webhook_id: String,
22}
23
24pub async fn create_webhook(
25 agent: &SolanaAgentKit,
26 account_addresses: Vec<String>,
27 webhook_url: String,
28) -> Result<HeliusWebhookResponse, Box<dyn std::error::Error>> {
29 let api_key = match agent.config.helius_api_key.as_ref() {
31 Some(key) => key,
32 None => return Err("Missing Helius API key in agent.config.HELIUS_API_KEY".into()),
33 };
34
35 let url = format!("https://api.helius.xyz/v0/webhooks?api-key={}", api_key);
36
37 let body = serde_json::json!({
38 "webhookURL": webhook_url,
39 "transactionTypes": ["Any"],
40 "accountAddresses": account_addresses,
41 "webhookType": "enhanced",
42 "txnStatus": "all",
43 });
44
45 let client = reqwest::Client::new();
46 let response = client.post(url).header("Content-Type", "application/json").json(&body).send().await?;
47
48 let data = response.json::<serde_json::Value>().await?;
49 let webhook_url = data.get("webhookURL").expect("webhookURL field").as_str().expect("webhookURL text");
50 let webhook_id = data.get("webhookID").expect("webhookID field").as_str().expect("webhookID text");
51
52 Ok(HeliusWebhookResponse { webhook_url: webhook_url.to_string(), webhook_id: webhook_id.to_string() })
53}