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
| Parameter | Type | Description |
|---|---|---|
rpc_client | &solana_client::rpc_client::RpcClient | Blocking client used to read primary-domain state. |
owner | &Pubkey | Wallet 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::InvalidNameAccountDatawhen a present state account is not owned by the name-offers program.SnsError::BorshErrorwhen the state data cannot be parsed asPrimaryDomain.SnsError::SolanaClientfor 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}");
}