Skip to main content

AnsClient

Struct AnsClient 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for AnsClient

Source§

fn clone(&self) -> AnsClient

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AnsClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more