sui::objectSui object identifiers
IDUIDid_to_bytesid_to_addressid_from_bytesid_from_addresssui_system_stateclockauthenticator_staterandomness_statesui_deny_list_object_idsui_accumulator_root_object_idsui_accumulator_root_addressbridgeuid_as_inneruid_to_inneruid_to_bytesuid_to_addressnewdeleteidborrow_idid_bytesid_addressborrow_uidnew_uid_from_hashdelete_implrecord_new_uiduse std::ascii;
use std::bcs;
use std::option;
use std::string;
use std::vector;
use sui::address;
use sui::hex;
use sui::tx_context;
IDAn object ID. This is used to reference Sui Objects.
This is not guaranteed to be globally unique–anyone can create an ID from a UID or
from an object, and ID’s can be freely copied and dropped.
Here, the values are not globally unique because there can be multiple values of type ID
with the same underlying bytes. For example, object::id(&obj) can be called as many times
as you want for a given obj, and each ID value will be identical.
public struct ID has copy, drop, store
bytes: address
UIDGlobally unique IDs that define an object’s ID in storage. Any Sui Object, that is a struct
with the key ability, must have id: UID as its first field.
These are globally unique in the sense that no two values of type UID are ever equal, in
other words for any two values id1: UID and id2: UID, id1 != id2.
This is a privileged type that can only be derived from a TxContext.
UID doesn’t have the drop ability, so deleting a UID requires a call to delete.
public struct UID has store
The hardcoded ID for the singleton Sui System State Object.
const SUI_SYSTEM_STATE_OBJECT_ID: address = 0x5;
The hardcoded ID for the singleton Clock Object.
const SUI_CLOCK_OBJECT_ID: address = 0x6;
The hardcoded ID for the singleton AuthenticatorState Object.
const SUI_AUTHENTICATOR_STATE_ID: address = 0x7;
The hardcoded ID for the singleton Random Object.
const SUI_RANDOM_ID: address = 0x8;
The hardcoded ID for the singleton DenyList.
const SUI_DENY_LIST_OBJECT_ID: address = 0x403;
The hardcoded ID for the singleton AccumulatorRoot Object.
const SUI_ACCUMULATOR_ROOT_OBJECT_ID: address = 0xacc;
The hardcoded ID for the Bridge Object.
const SUI_BRIDGE_ID: address = 0x9;
Sender is not @0x0 the system address.
const ENotSystemAddress: u64 = 0;
id_to_bytesGet the raw bytes of a ID
public fun id_to_bytes(id: &sui::object::ID): vector<u8>
public fun id_to_bytes(id: &ID): vector<u8> {
bcs::to_bytes(&id.bytes)
}
id_to_addressGet the inner bytes of id as an address.
public fun id_to_address(id: &sui::object::ID): address
public fun id_to_address(id: &ID): address {
id.bytes
}
id_from_bytesMake an ID from raw bytes.
public fun id_from_bytes(bytes: vector<u8>): sui::object::ID
public fun id_from_bytes(bytes: vector<u8>): ID {
address::from_bytes(bytes).to_id()
}
id_from_addressMake an ID from an address.
public fun id_from_address(bytes: address): sui::object::ID
public fun id_from_address(bytes: address): ID {
ID { bytes }
}
sui_system_stateCreate the UID for the singleton SuiSystemState object.
This should only be called once from sui_system.
fun sui_system_state(ctx: &sui::tx_context::TxContext): sui::object::UID
fun sui_system_state(ctx: &TxContext): UID {
assert!(ctx.sender() == @0x0, ENotSystemAddress);
UID {
id: ID { bytes: SUI_SYSTEM_STATE_OBJECT_ID },
}
}
clockCreate the UID for the singleton Clock object.
This should only be called once from clock.
public(package) fun clock(): sui::object::UID
authenticator_stateCreate the UID for the singleton AuthenticatorState object.
This should only be called once from authenticator_state.
public(package) fun authenticator_state(): sui::object::UID
public(package) fun authenticator_state(): UID {
UID {
id: ID { bytes: SUI_AUTHENTICATOR_STATE_ID },
}
}
randomness_stateCreate the UID for the singleton Random object.
This should only be called once from random.
public(package) fun randomness_state(): sui::object::UID
public(package) fun randomness_state(): UID {
UID {
id: ID { bytes: SUI_RANDOM_ID },
}
}
sui_deny_list_object_idCreate the UID for the singleton DenyList object.
This should only be called once from deny_list.
public(package) fun sui_deny_list_object_id(): sui::object::UID
public(package) fun sui_deny_list_object_id(): UID {
UID {
id: ID { bytes: SUI_DENY_LIST_OBJECT_ID },
}
}
sui_accumulator_root_object_idpublic(package) fun sui_accumulator_root_object_id(): sui::object::UID
public(package) fun sui_accumulator_root_object_id(): UID {
UID {
id: ID { bytes: SUI_ACCUMULATOR_ROOT_OBJECT_ID },
}
}
sui_accumulator_root_addresspublic(package) fun sui_accumulator_root_address(): address
public(package) fun sui_accumulator_root_address(): address {
SUI_ACCUMULATOR_ROOT_OBJECT_ID
}
bridgeCreate the UID for the singleton Bridge object.
This should only be called once from bridge.
fun bridge(): sui::object::UID
uid_as_innerGet the inner ID of uid
public fun uid_as_inner(uid: &sui::object::UID): &sui::object::ID
public fun uid_as_inner(uid: &UID): &ID {
&uid.id
}
uid_to_innerGet the raw bytes of a uid’s inner ID
public fun uid_to_inner(uid: &sui::object::UID): sui::object::ID
public fun uid_to_inner(uid: &UID): ID {
uid.id
}
uid_to_bytesGet the raw bytes of a UID
public fun uid_to_bytes(uid: &sui::object::UID): vector<u8>
public fun uid_to_bytes(uid: &UID): vector<u8> {
bcs::to_bytes(&uid.id.bytes)
}
uid_to_addressGet the inner bytes of id as an address.
public fun uid_to_address(uid: &sui::object::UID): address
public fun uid_to_address(uid: &UID): address {
uid.id.bytes
}
newCreate a new object. Returns the UID that must be stored in a Sui object.
This is the only way to create UIDs.
public fun new(ctx: &mut sui::tx_context::TxContext): sui::object::UID
public fun new(ctx: &mut TxContext): UID {
UID {
id: ID { bytes: ctx.fresh_object_address() },
}
}
deleteDelete the object and its UID. This is the only way to eliminate a UID.
This exists to inform Sui of object deletions. When an object
gets unpacked, the programmer will have to do something with its
UID. The implementation of this function emits a deleted
system event so Sui knows to process the object deletion
public fun delete(id: sui::object::UID)
idGet the underlying ID of obj
public fun id<T: key>(obj: &T): sui::object::ID
public fun id<T: key>(obj: &T): ID {
borrow_uid(obj).id
}
borrow_idBorrow the underlying ID of obj
public fun borrow_id<T: key>(obj: &T): &sui::object::ID
public fun borrow_id<T: key>(obj: &T): &ID {
&borrow_uid(obj).id
}
id_bytesGet the raw bytes for the underlying ID of obj
public fun id_bytes<T: key>(obj: &T): vector<u8>
public fun id_bytes<T: key>(obj: &T): vector<u8> {
bcs::to_bytes(&borrow_uid(obj).id)
}
id_addressGet the inner bytes for the underlying ID of obj
public fun id_address<T: key>(obj: &T): address
public fun id_address<T: key>(obj: &T): address {
borrow_uid(obj).id.bytes
}
borrow_uidGet the UID for obj.
Safe because Sui has an extra bytecode verifier pass that forces every struct with
the key ability to have a distinguished UID field.
Cannot be made public as the access to UID for a given object must be privileged, and
restrictable in the object’s module.
fun borrow_uid<T: key>(obj: &T): &sui::object::UID
native fun borrow_uid<T: key>(obj: &T): &UID;
new_uid_from_hashGenerate a new UID specifically used for creating a UID from a hash
public(package) fun new_uid_from_hash(bytes: address): sui::object::UID
public(package) fun new_uid_from_hash(bytes: address): UID {
record_new_uid(bytes);
UID { id: ID { bytes } }
}
delete_implfun delete_impl(id: address)
native fun delete_impl(id: address);
record_new_uidfun record_new_uid(id: address)
native fun record_new_uid(id: address);