helius_rust_client/client/
names.rs

1use super::{
2    init::{HeliusClient, API_URL_V0},
3    parse_response,
4};
5use serde::Deserialize;
6use solana_client::client_error::Result as ClientResult;
7
8#[derive(Deserialize, Debug, PartialEq)]
9#[serde(rename_all = "camelCase")]
10struct DomainNamesResponse {
11    domain_names: Vec<String>,
12}
13
14impl HeliusClient {
15    /// Returns the Solana Naming Service name for a given address. GET request to `https://api.helius.xyz/v0/addresses/{address}/names`.
16    /// * `address` - The address that you want names for.
17    pub async fn get_naming_service_names(&self, address: String) -> ClientResult<Vec<String>> {
18        let request_url = format!(
19            "{}/addresses/{}/names?api-key={}",
20            API_URL_V0, address, self.api_key
21        );
22
23        let response = self
24            .http_client
25            .get(request_url)
26            .header("accept", "application/json")
27            .header("Content-Type", "application/json")
28            .send()
29            .await;
30
31        let response: DomainNamesResponse = parse_response(response).await?;
32        Ok(response.domain_names)
33    }
34}