Address

Struct Address 

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

Unique identifier for an Account on the Sui blockchain.

An Address is a 32-byte pseudonymous identifier used to uniquely identify an account and asset-ownership on the Sui blockchain. Often, human-readable addresses are encoded in hexadecimal with a 0x prefix. For example, this is a valid Sui address: 0x02a212de6a9dfa3a69e22387acfbafbb1a9e591bd9d636e7895dcfc8de05f331.

use sui_sdk_types::Address;

let hex = "0x02a212de6a9dfa3a69e22387acfbafbb1a9e591bd9d636e7895dcfc8de05f331";
let address = Address::from_hex(hex).unwrap();
println!("Address: {}", address);
assert_eq!(hex, address.to_string());

§Deriving an account Address

Account addresses are cryptographically derived from a number of user account authenticators, the simplest of which is an Ed25519PublicKey.

Deriving an address consists of the Blake2b256 hash of the sequence of bytes of its corresponding authenticator, prefixed with a domain-separator. For each authenticator, this domain-separator is the single byte-value of its SignatureScheme flag. E.g. hash(signature schema flag || authenticator bytes).

Each authenticator includes a convince method for deriving its Address as well as documentation for the specifics of how the derivation is done. See Ed25519PublicKey::derive_address for an example.

§Usage as ObjectIds

Addresses are also used as a way to uniquely identify an Object. When an Address is used as an object identifierit can also be referred to as an ObjectId. ObjectIds and account Addresses share the same 32-byte addressable space but are derived leveraging different domain-separator values to ensure, cryptographically, that there won’t be any overlap, e.g. there can’t be a valid Object whose ObjectId is equal to that of the Address of a user account.

§BCS

An Address’s BCS serialized form is defined by the following:

address = 32OCTET

Implementations§

Source§

impl Address

Source

pub const LENGTH: usize = 32usize

Source

pub const ZERO: Address

Source

pub const TWO: Address

Source

pub const THREE: Address

Source

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

Source

pub const fn into_inner(self) -> [u8; 32]

Return the underlying byte array of a Address.

Source

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

Source

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

Source

pub fn from_hex<T>(hex: T) -> Result<Address, AddressParseError>
where T: AsRef<[u8]>,

Decodes an address from a hex encoded string.

Source

pub const fn from_hex_unwrap(hex: &[u8]) -> Address

Decodes an address from a hex encoded string.

Similar to from_hex except any errors are unwrapped, turning them into panics.

Source

pub fn to_hex(&self) -> String

Source

pub fn from_bytes<T>(bytes: T) -> Result<Address, AddressParseError>
where T: AsRef<[u8]>,

Trait Implementations§

Source§

impl AsRef<[u8]> for Address

Source§

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

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

impl AsRef<[u8; 32]> for Address

Source§

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

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

impl Clone for Address

Source§

fn clone(&self) -> Address

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 Address

Source§

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

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

impl<'de> Deserialize<'de> for Address

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Address, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

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

impl Display for Address

Source§

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

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

impl From<[u8; 32]> for Address

Source§

fn from(address: [u8; 32]) -> Address

Converts to this type from the input type.
Source§

impl From<Address> for ID

Source§

fn from(value: Address) -> Self

Converts to this type from the input type.
Source§

impl From<Address> for UID

Source§

fn from(value: Address) -> Self

Converts to this type from the input type.
Source§

impl From<Address> for Vec<u8>

Source§

fn from(value: Address) -> Vec<u8>

Converts to this type from the input type.
Source§

impl From<ID> for Address

Source§

fn from(value: ID) -> Self

Converts to this type from the input type.
Source§

impl From<UID> for Address

Source§

fn from(value: UID) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Address

Source§

type Err = AddressParseError

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

fn from_str(s: &str) -> Result<Address, <Address as FromStr>::Err>

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

impl Hash for Address

Source§

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

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 MoveType for Address

Source§

type TypeTag = AddressTypeTag

Source§

fn from_bcs(bytes: &[u8]) -> Result<Self, Error>

Deserialize the contents of the Move type from BCS bytes.
Source§

fn into_bcs(self) -> Result<Vec<u8>, Error>

Consuming version of to_bcs.
Source§

fn to_bcs(&self) -> Result<Vec<u8>, Error>

Serialize the contents of the Move type to BCS bytes.
Source§

fn into_json(self) -> Value

Consuming version of to_json.
Source§

fn to_json(&self) -> Value

Serialize the contents of the Move type to JSON. Read more
Source§

impl Ord for Address

Source§

fn cmp(&self, other: &Address) -> 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 Address

Source§

fn eq(&self, other: &Address) -> 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 Address

Source§

fn partial_cmp(&self, other: &Address) -> 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 Address

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

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

impl StaticTypeTag for Address

Source§

impl Copy for Address

Source§

impl Eq for Address

Source§

impl StructuralPartialEq for Address

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<U> As for U

Source§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. 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.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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, 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,