Skip to main content

AccountAddress

Struct AccountAddress 

Source
pub struct AccountAddress(/* private fields */);
Expand description

A 32-byte Aptos account address.

Account addresses on Aptos are derived from public keys through a specific derivation scheme that includes an authentication key prefix.

§Display Format (AIP-40)

The Display trait follows AIP-40:

  • Special addresses (0x1 through 0xf) use SHORT format: 0x1, 0x3, 0xa
  • Normal addresses use LONG format: full 64 hex characters with 0x prefix

Use to_long_string() to always get the full 64-character format, or to_short_string() to always get the trimmed format.

§Example

use aptos_sdk::AccountAddress;

// Parse from hex string
let addr = AccountAddress::from_hex("0x1").unwrap();

// Display uses AIP-40: SHORT for special addresses
assert_eq!(addr.to_string(), "0x1");

// Explicit long/short string methods
assert_eq!(addr.to_long_string(), "0x0000000000000000000000000000000000000000000000000000000000000001");
assert_eq!(addr.to_short_string(), "0x1");

Implementations§

Source§

impl AccountAddress

Source

pub const ZERO: Self

The “zero” address (all zeros).

Source

pub const ONE: Self

The core framework address (0x1).

Source

pub const THREE: Self

The token framework address (0x3).

Source

pub const FOUR: Self

The fungible asset framework address (0x4).

Source

pub const A: Self

The APT fungible asset metadata address (0xa).

Source

pub const fn new(bytes: [u8; 32]) -> Self

Creates an address from a byte array.

Source

pub fn from_hex<T: AsRef<[u8]>>(hex_str: T) -> AptosResult<Self>

Creates an address from a hex string (with or without 0x prefix).

The hex string must contain at least one hex digit. Empty strings and bare “0x” prefixes are rejected as invalid addresses.

§Errors

Returns an error if the input is empty, contains invalid UTF-8, has no hex digits after the prefix, exceeds the maximum length (64 hex characters), or contains invalid hex characters.

Source

pub fn from_bytes<T: AsRef<[u8]>>(bytes: T) -> AptosResult<Self>

Creates an address from a byte slice.

§Errors

Returns an error if the byte slice is not exactly 32 bytes long.

Source

pub fn as_bytes(&self) -> &[u8]

Returns the address as a byte slice.

Source

pub fn to_bytes(&self) -> [u8; 32]

Returns the address as a byte array.

Source

pub fn to_hex(&self) -> String

Returns the address as a hex string with 0x prefix (always 66 characters).

This is an alias for to_long_string().

Source

pub fn to_long_string(&self) -> String

Returns the full 64-character hex string with 0x prefix.

This always returns the LONG format regardless of whether the address is special. For example, 0x1 becomes 0x0000000000000000000000000000000000000000000000000000000000000001.

Source

pub fn to_short_string(&self) -> String

Returns a short hex string, trimming leading zeros.

For example, 0x0000...0001 becomes 0x1.

Source

pub fn to_standard_string(&self) -> String

Returns the standard string representation following AIP-40.

  • Special addresses (0x1 through 0xf) use SHORT format
  • Normal addresses use LONG format (full 64 hex characters)
Source

pub fn is_zero(&self) -> bool

Returns true if this is the zero address.

Source

pub fn is_special(&self) -> bool

Returns true if this is a “special” address (first 63 bytes are zero, and the last byte is non-zero and less than 16).

Special addresses include framework addresses like 0x1, 0x3, 0x4.

Trait Implementations§

Source§

impl AsRef<[u8]> for AccountAddress

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for AccountAddress

Source§

fn clone(&self) -> AccountAddress

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for AccountAddress

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for AccountAddress

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for AccountAddress

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for AccountAddress

Source§

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

Formats the address following AIP-40:

  • Special addresses (0x1 through 0xf) use SHORT format
  • Normal addresses use LONG format (full 64 hex characters)
Source§

impl From<[u8; 32]> for AccountAddress

Source§

fn from(bytes: [u8; 32]) -> Self

Converts to this type from the input type.
Source§

impl From<AccountAddress> for [u8; 32]

Source§

fn from(addr: AccountAddress) -> Self

Converts to this type from the input type.
Source§

impl From<AuthenticationKey> for AccountAddress

Source§

fn from(key: AuthenticationKey) -> Self

Converts to this type from the input type.
Source§

impl FromStr for AccountAddress

Source§

type Err = AptosError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for AccountAddress

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for AccountAddress

Source§

fn cmp(&self, other: &AccountAddress) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for AccountAddress

Source§

fn eq(&self, other: &AccountAddress) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for AccountAddress

Source§

fn partial_cmp(&self, other: &AccountAddress) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for AccountAddress

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for AccountAddress

Source§

impl Eq for AccountAddress

Source§

impl StructuralPartialEq for AccountAddress

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<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

impl<T> IntoMoveArg for T
where T: Serialize,

Source§

fn into_move_arg(self) -> Result<Vec<u8>, AptosError>

Converts this value into BCS-encoded bytes. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: 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> ToHex for T
where T: AsRef<[u8]>,

Source§

fn encode_hex<U>(&self) -> U
where U: FromIterator<char>,

Encode the hex strict representing self into the result. Lower case letters are used (e.g. f9b4ca)
Source§

fn encode_hex_upper<U>(&self) -> U
where U: FromIterator<char>,

Encode the hex strict representing self into the result. Upper case letters are used (e.g. F9B4CA)
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,