A comprehensive repository demonstrating the use of derived objects in Sui Move, showcasing deterministic address generation and various practical use cases.
Derived objects in Sui provide a way to create deterministic addresses based on a parent object and a key. This enables:
- Predictable Addresses: Generate addresses that can be computed off-chain before object creation
- One-per-key Uniqueness: Ensure only one object exists per key for a given parent
- Efficient Discovery: Easily find objects without querying or maintaining indices
- Parallel Processing: Avoid bottlenecks by not requiring parent object modifications
sui-derived-objects/
├── sources/
│ ├── derived_vault.move # Vault with deterministic addresses
│ └── deterministic_addresses.move # User accounts at predictable addresses
├── tests/
│ └── derived_vault_tests.move # Test suite
├── scripts/
│ └── deploy.sh # Deployment script
└── Move.toml # Package manifest
A vault system where each user has a vault at a deterministic address derived from their account address.
Key Features:
- One vault per user at a predictable address
- Deposit and withdrawal functionality
- Balance tracking using Sui's native Balance type
- Transfer-to-derived-address pattern for receiving funds
Usage:
// Create a vault (transfers to derived address)
derived_vault::create_vault(registry, ctx);
// Get vault address (can be computed off-chain)
let vault_addr = derived_vault::get_vault_address(registry, user);
// Send funds to vault's derived address
derived_vault::deposit_to_derived(registry, recipient, payment);
// Withdraw from vault
derived_vault::withdraw(vault, amount, ctx);A registry system for user accounts that live at deterministic addresses, enabling direct messaging and interactions.
Key Features:
- User registration with unique usernames
- Deterministic account addresses based on user address
- Direct messaging between accounts
- Account discovery without database queries
Usage:
// Register an account at deterministic address
deterministic_addresses::register_account(registry, username, ctx);
// Get account address (computable off-chain)
let account_addr = deterministic_addresses::get_account_address(registry, user);
// Send message to another user's account
deterministic_addresses::send_message(registry, recipient, content, ctx);
// Receive messages at your account
deterministic_addresses::receive_message(account, message, ctx);Addresses are derived using a parent object's ID and a key:
let address = derived_object::derive_address(parent_id, key);This creates a deterministic address that:
- Is unique for each parent-key combination
- Can be computed without on-chain state access
- Remains constant across time
To mark a derived object as "claimed" and prevent duplicates:
let uid = derived_object::claim(&mut parent.id, key);
// In current Sui version, we delete the UID if using transfer pattern
object::delete(uid);Since Sui's verifier requires fresh UIDs from object::new(), we use a transfer pattern:
- Create object with fresh UID from
object::new() - Transfer it to the derived address
- Mark the derived address as claimed
- Sui CLI installed (Installation Guide)
- Git for cloning the repository
sui move buildsui move testStore user preferences at predictable addresses without maintaining a central index.
Create non-transferable tokens at derived addresses tied to user identities.
Send funds to addresses before accounts are created, enabling gasless onboarding.
Use deterministic addresses for bridge contracts to enable predictable cross-chain transfers.
Build registries where each entry lives at a predictable address based on its key.
// Create object and transfer to derived address
let obj = Object { id: object::new(ctx), ... };
let derived_addr = derived_object::derive_address(parent_id, key);
transfer::transfer(obj, derived_addr);// Receive objects sent to derived address
public entry fun receive_at_derived(
obj: &mut Object,
receiving: Receiving<Item>,
ctx: &TxContext
) {
let item = transfer::public_receive(&mut obj.id, receiving);
// Process item...
}// Check if derived object exists before creation
if (!derived_object::exists(&parent.id, key)) {
// Create new object...
}- Use Unique Keys: Ensure keys are unique to prevent ID collisions
- Document Derived Addresses: Make it clear which addresses are derived
- Handle Missing Objects: Always check existence before assuming objects exist
- Consider Discovery: Derived addresses improve discoverability
- Plan for Immutability: Derived addresses cannot be changed once created
- No Central Registry: Objects are discoverable without maintaining indices
- Parallel Processing: No bottleneck on parent object access
- Gas Efficiency: Reduced storage and computation costs
- Composability: Easy integration with other protocols
- Predictability: Addresses can be computed off-chain
- Derived addresses are deterministic - anyone can compute them
- Ensure proper access controls on derived objects
- Consider privacy implications of predictable addresses
- Validate ownership before allowing operations
This project is provided as-is for educational purposes. Use at your own risk.
Hola, Sele here. If you have any issues, complaints or feedback, notify me. Or text my grandma on Telegram (SeventhOdyssey71)