pub struct AnsClient { /* private fields */ }Expand description
Client for the Aptos Names Service.
Cheap to clone (wraps a FullnodeClient). See the module docs for
usage and network support.
Implementations§
Source§impl AnsClient
impl AnsClient
Sourcepub fn new(fullnode: FullnodeClient) -> Self
pub fn new(fullnode: FullnodeClient) -> Self
Constructs an ANS client that resolves the router contract address
from the fullnode’s configured network (mainnet / testnet / localnet).
For networks without a built-in ANS deployment (devnet, custom), use
with_router_address instead; calls on a
client built with new for such a network return an error.
Sourcepub fn with_router_address(
fullnode: FullnodeClient,
router_address: AccountAddress,
) -> Self
pub fn with_router_address( fullnode: FullnodeClient, router_address: AccountAddress, ) -> Self
Constructs an ANS client pinned to an explicit router contract
address.
Use this for devnet, custom networks, or a privately deployed ANS where the contract address is not built in.
Sourcepub fn router_address(&self) -> AptosResult<AccountAddress>
pub fn router_address(&self) -> AptosResult<AccountAddress>
Returns the resolved router contract address for this client.
§Errors
Returns AptosError::Config if no override was supplied and the
configured network has no known ANS deployment.
Sourcepub async fn get_target_address(
&self,
name: &str,
) -> AptosResult<Option<AccountAddress>>
pub async fn get_target_address( &self, name: &str, ) -> AptosResult<Option<AccountAddress>>
Resolves the target address a name points to (where it resolves to),
or None if the name is unregistered or has no target set.
This is the address callers usually want when “looking up a name”. It is
distinct from the owner address (see
get_owner_address).
§Errors
Returns an error if the network has no ANS deployment, the name is invalid, or the underlying view call fails.
Sourcepub async fn get_owner_address(
&self,
name: &str,
) -> AptosResult<Option<AccountAddress>>
pub async fn get_owner_address( &self, name: &str, ) -> AptosResult<Option<AccountAddress>>
Resolves the owner address of a name (the account that controls the
registration), or None if the name is unregistered.
§Errors
Returns an error if the network has no ANS deployment, the name is invalid, or the underlying view call fails.
Sourcepub async fn get_primary_name(
&self,
address: AccountAddress,
) -> AptosResult<Option<String>>
pub async fn get_primary_name( &self, address: AccountAddress, ) -> AptosResult<Option<String>>
Returns the primary name registered to an address (as a fully qualified
name without the .apt suffix, e.g. wallet.alice or alice), or
None if the address has no primary name.
§Errors
Returns an error if the network has no ANS deployment or the underlying view call fails.
Sourcepub async fn get_expiration(&self, name: &str) -> AptosResult<Option<u64>>
pub async fn get_expiration(&self, name: &str) -> AptosResult<Option<u64>>
Returns the expiration timestamp of a name in seconds since the Unix
epoch, or None if the name is unregistered.
Note: the TypeScript SDK returns milliseconds; this returns the raw on-chain value in seconds. Multiply by 1000 for millisecond parity.
§Errors
Returns an error if the network has no ANS deployment, the name is
invalid, or the view call fails. A missing name is reported as
Ok(None), not an error: the Move view aborts, which the node surfaces
as an HTTP 400 carrying the abort code. Other API failures (rate limits,
5xx, malformed requests) propagate so transient/operational problems are
not mistaken for an unregistered name.
Sourcepub async fn lookup(&self, name: &str) -> AptosResult<AccountAddress>
pub async fn lookup(&self, name: &str) -> AptosResult<AccountAddress>
Resolves a name to its target address, erroring if it does not resolve.
This is a convenience wrapper over
get_target_address for callers that treat
an unresolved name as an error.
§Errors
Returns AptosError::NotFound if the name does not resolve to an
address, plus any error from
get_target_address.
Sourcepub async fn reverse_lookup(
&self,
address: AccountAddress,
) -> AptosResult<Option<String>>
pub async fn reverse_lookup( &self, address: AccountAddress, ) -> AptosResult<Option<String>>
Returns the primary name registered to an address, if any.
Alias for get_primary_name.
§Errors
Returns an error if the network has no ANS deployment or the underlying view call fails.
Sourcepub fn register_domain_payload(
&self,
name: &str,
registration_duration_secs: u64,
target_address: Option<AccountAddress>,
to_address: Option<AccountAddress>,
) -> AptosResult<EntryFunction>
pub fn register_domain_payload( &self, name: &str, registration_duration_secs: u64, target_address: Option<AccountAddress>, to_address: Option<AccountAddress>, ) -> AptosResult<EntryFunction>
Builds the payload to register a top-level domain for the given duration (in seconds).
target_address is the address the name will resolve to (defaults to
the sender on-chain when None); to_address is the account that will
own the registration (defaults to the sender when None).
§Errors
Returns an error if the network has no ANS deployment, the name is invalid, the name has a subdomain (use a subdomain-specific flow), or argument encoding fails.
Sourcepub fn set_primary_name_payload(&self, name: &str) -> AptosResult<EntryFunction>
pub fn set_primary_name_payload(&self, name: &str) -> AptosResult<EntryFunction>
Builds the payload to set the sender’s primary name to name.
§Errors
Returns an error if the network has no ANS deployment, the name is invalid, or argument encoding fails.
Sourcepub fn clear_primary_name_payload(&self) -> AptosResult<EntryFunction>
pub fn clear_primary_name_payload(&self) -> AptosResult<EntryFunction>
Builds the payload to clear the sender’s primary name.
§Errors
Returns an error if the network has no ANS deployment.
Sourcepub fn set_target_address_payload(
&self,
name: &str,
address: AccountAddress,
) -> AptosResult<EntryFunction>
pub fn set_target_address_payload( &self, name: &str, address: AccountAddress, ) -> AptosResult<EntryFunction>
Builds the payload to point name at address (set its target
address).
§Errors
Returns an error if the network has no ANS deployment, the name is invalid, or argument encoding fails.
Sourcepub fn clear_target_address_payload(
&self,
name: &str,
) -> AptosResult<EntryFunction>
pub fn clear_target_address_payload( &self, name: &str, ) -> AptosResult<EntryFunction>
Builds the payload to clear the target address of name.
§Errors
Returns an error if the network has no ANS deployment, the name is invalid, or argument encoding fails.