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
0xprefix
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
impl AccountAddress
Sourcepub fn from_hex<T: AsRef<[u8]>>(hex_str: T) -> AptosResult<Self>
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.
Sourcepub fn from_bytes<T: AsRef<[u8]>>(bytes: T) -> AptosResult<Self>
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.
Sourcepub fn to_hex(&self) -> String
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().
Sourcepub fn to_long_string(&self) -> String
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.
Sourcepub fn to_short_string(&self) -> String
pub fn to_short_string(&self) -> String
Returns a short hex string, trimming leading zeros.
For example, 0x0000...0001 becomes 0x1.
Sourcepub fn to_standard_string(&self) -> String
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)
Sourcepub fn is_special(&self) -> bool
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
impl AsRef<[u8]> for AccountAddress
Source§impl Clone for AccountAddress
impl Clone for AccountAddress
Source§fn clone(&self) -> AccountAddress
fn clone(&self) -> AccountAddress
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AccountAddress
impl Debug for AccountAddress
Source§impl Default for AccountAddress
impl Default for AccountAddress
Source§impl<'de> Deserialize<'de> for AccountAddress
impl<'de> Deserialize<'de> for AccountAddress
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Display for AccountAddress
impl Display for AccountAddress
Source§impl From<AccountAddress> for [u8; 32]
impl From<AccountAddress> for [u8; 32]
Source§fn from(addr: AccountAddress) -> Self
fn from(addr: AccountAddress) -> Self
Source§impl From<AuthenticationKey> for AccountAddress
impl From<AuthenticationKey> for AccountAddress
Source§fn from(key: AuthenticationKey) -> Self
fn from(key: AuthenticationKey) -> Self
Source§impl FromStr for AccountAddress
impl FromStr for AccountAddress
Source§impl Hash for AccountAddress
impl Hash for AccountAddress
Source§impl Ord for AccountAddress
impl Ord for AccountAddress
Source§fn cmp(&self, other: &AccountAddress) -> Ordering
fn cmp(&self, other: &AccountAddress) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for AccountAddress
impl PartialEq for AccountAddress
Source§impl PartialOrd for AccountAddress
impl PartialOrd for AccountAddress
Source§impl Serialize for AccountAddress
impl Serialize for AccountAddress
impl Copy for AccountAddress
impl Eq for AccountAddress
impl StructuralPartialEq for AccountAddress
Auto Trait Implementations§
impl Freeze for AccountAddress
impl RefUnwindSafe for AccountAddress
impl Send for AccountAddress
impl Sync for AccountAddress
impl Unpin for AccountAddress
impl UnwindSafe for AccountAddress
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoMoveArg for Twhere
T: Serialize,
impl<T> IntoMoveArg for Twhere
T: Serialize,
Source§fn into_move_arg(self) -> Result<Vec<u8>, AptosError>
fn into_move_arg(self) -> Result<Vec<u8>, AptosError>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Lower case
letters are used (e.g. f9b4ca)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Upper case
letters are used (e.g. F9B4CA)Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.