Predict a Sui object address before claiming it
A ticket service can publish a predictable ticket address without maintaining a sequence of randomly assigned object IDs. Sui derives it from the parent and a typed key.
Use precisely the key type used by the contract
Inside the module owning the parent, compare a prediction with the UID returned by claim. The excerpt assumes a Ticket object whose only field is its UID. Return or transfer the completed ticket according to the application’s ownership rules.
let predicted = sui::derived_object::derive_address(parent.id.to_inner(), 42u64);
let uid = sui::derived_object::claim(&mut parent.id, 42u64);
assert!(uid.to_address() == predicted, 0);
let ticket = Ticket { id: uid };
Treat a claim as a permanent reservation
A u64 key of 42 differs from the UTF-8 bytes for “42”. Save the parent ID, type and value when generating links. Deleting the resulting ticket does not clear the reservation recorded on the parent. A second claim for the same typed key aborts, so handle replacement tickets with a distinct application key.