Understand Move’s ability system that controls how types can be used and manipulated.
Abilities in Move are constraints on types that control what operations can be performed on them. They’re fundamental to Move’s resource safety guarantees.
public struct Point has copy, drop { x: u64, y: u64,}let p1 = Point { x: 1, y: 2 };let p2 = p1; // OK: Point has copylet p3 = p1; // Still OK: p1 is still valid
Objects with UID cannot have copy ability because UIDs must be unique.
public struct MyObject has key { id: UID, // Required for key data: vector<u8>,}public struct NotAnObject has store { value: u64, // No key = not an object}
Types with key must have id: UID as their first field.
// Require specific abilitiespublic struct Box<T: store> has key, store { id: UID, value: T, // T must have store}public fun transfer_box<T: key + store>(box: Box<T>, recipient: address) { transfer::public_transfer(box, recipient);}
public struct Coin<phantom T> has key, store { id: UID, balance: u64,}// T doesn't need any abilities because it's phantompublic struct USD {} // No abilities neededlet coin: Coin<USD> = /* ... */;