Skip to main content

Rust SDK API Reference / Primary domains / get_primary_domain

Function: get_primary_domain()

pub fn get_primary_domain(
rpc_client: &RpcClient,
owner: &Pubkey,
) -> Result<Option<Pubkey>, SnsError>

Defined in: rust-crates/sns-sdk/src/blocking/primary_domain.rs:10

Derives the wallet's primary-domain state account and reads its selected SNS name account.

Availability

Requires the blocking feature.

Parameters

ParameterTypeDescription
rpc_client&solana_client::rpc_client::RpcClientBlocking client used to read primary-domain state.
owner&PubkeyWallet whose primary domain is requested.

Returns

Result<Option<Pubkey>, SnsError>. Some is the selected name-account key; None means no primary-domain state account exists.

Errors

  • SnsError::InvalidNameAccountData when a present state account is not owned by the name-offers program.
  • SnsError::BorshError when the state data cannot be parsed as PrimaryDomain.
  • SnsError::SolanaClient for RPC failures.

Example

use sns_sdk::blocking::primary_domain::get_primary_domain;
use solana_client::rpc_client::RpcClient;
use solana_program::pubkey::Pubkey;

let client = RpcClient::new("https://your-rpc-endpoint.example".to_string());
let owner: Pubkey = std::env::var("OWNER")?.parse()?;
if let Some(domain_key) = get_primary_domain(&client, &owner)? {
println!("{domain_key}");
}