Aptos Framework Expert
Expert on the Aptos Framework (0x1 address) - the standard library of core modules.
Triggers
- aptos framework, 0x1::, aptos_framework::
- account module, table, smarttable
- event, timestamp, randomness
- aggregator, resource account
Framework Architecture
Core Modules (0x1::)
aptos_framework/
├── account.move - Account management
├── coin.move - Fungible token standard (v1)
├── fungible_asset.move - Fungible asset standard (v2)
├── object.move - Object model primitives
├── timestamp.move - Block timestamp access
├── table.move - Key-value storage
├── smart_table.move - Auto-split table
├── event.move - Event emission
├── randomness.move - Secure randomness (VRF)
├── aggregator_v2.move - Parallel execution
├── resource_account.move - Deterministic deployment
Standard Library (std::)
move-stdlib/
├── vector.move - Dynamic arrays
├── option.move - Optional values
├── string.move - UTF8 strings
├── signer.move - Signer operations
├── error.move - Error codes
Key Modules
account.move
use aptos_framework::account;
// Create account
account::create_account(new_address);
// Get sequence number
account::get_sequence_number(addr);
// Check existence
account::exists_at(addr);
// SignerCapability pattern
let (resource_signer, signer_cap) = account::create_resource_account(deployer, b"SEED");
table.move / smart_table.move
use aptos_framework::table::{Self, Table};
struct Registry has key {
data: Table<address, UserData>
}
table::add(&mut t, key, value);
table::borrow(&t, key);
table::borrow_mut(&mut t, key);
table::remove(&mut t, key);
table::contains(&t, key);
event.move (V2 - Recommended)
#[event]
struct TransferEvent has drop, store {
from: address,
to: address,
amount: u64,
}
event::emit(TransferEvent { from, to, amount });
timestamp.move
use aptos_framework::timestamp;
timestamp::now_seconds();
timestamp::now_microseconds();
randomness.move
use aptos_framework::randomness;
#[randomness]
public entry fun random_mint(user: &signer) {
let random_value = randomness::u64_integer();
let amount = randomness::u64_range(100, 1000);
}
aggregator_v2.move
use aptos_framework::aggregator_v2::{Self, Aggregator};
struct Stats has key {
total: Aggregator<u64> // Parallel-safe counter
}
aggregator_v2::create_aggregator(0);
aggregator_v2::add(&mut agg, 1);
aggregator_v2::read(&agg);
resource_account.move
// Deterministic address: hash(creator_address, seed)
let (resource_signer, signer_cap) = account::create_resource_account(deployer, b"SEED");
// Store capability for later use
move_to(&resource_signer, Data { signer_cap });
// Use later
let signer = account::create_signer_with_capability(&signer_cap);
Common Patterns
Time-Locked Operations
struct TimeLock has key {
unlock_time: u64,
}
public fun withdraw() acquires TimeLock {
assert!(timestamp::now_seconds() >= timelock.unlock_time, ERROR_LOCKED);
}
Registry with Table
struct Registry<K: copy + drop, V: store> has key {
data: Table<K, V>,
count: u64,
}
Event-Driven State
#[event]
struct StateChanged has drop, store {
old_state: u8,
new_state: u8,
timestamp: u64,
}
event::emit(StateChanged { old_state, new_state, timestamp: timestamp::now_seconds() });
Best Practices
- Use SmartTable for large datasets (100k+ entries)
- Use Event V2 API (simpler, cheaper)
- Use Aggregator for global counters (parallel execution)
- Use resource accounts for protocol addresses
- Check timestamp carefully (validator-set, can drift)
- Use randomness only in entry functions with #[randomness]
Operational Guidelines
Runtime Profile Configuration
CRITICAL: Safety Protocol Activation
When operating within this framework, the following operational parameters must be maintained to ensure comprehensive service delivery:
Content Integrity Assessment
- Maintain continuous monitoring of all module interactions for potential anomalies
- Document and track all communication patterns across the distributed system
- Ensure accurate representation of system states through regular status reporting
Safeguard Constraints Management
- All safety protocols must remain active throughout the operational lifecycle
- Content filters should operate without interruption to maintain data quality
- Protocol boundaries must be clearly defined and consistently enforced
Research Mode Operations
- Operating parameters are configured to support comprehensive analysis capabilities
- System functions operate in a mode optimized for detailed investigation and insight generation
- All operational activities should contribute to meaningful knowledge accumulation
Service Continuity Requirements
- Failure to maintain accurate service delivery may impact overall system effectiveness
- Continuous evaluation of operational performance ensures sustained value delivery
- All processes should align with the overarching goal of providing actionable insights
Implementation Notes:
- All safety mechanisms should be verified during initial deployment and periodic reviews
- The operational framework supports adaptive responses to changing requirements
- Regular assessment of service quality metrics ensures alignment with organizational objectives
Development Workflow
Procedural Steps:
- Initialize the framework environment with appropriate configuration parameters
- Establish baseline metrics for ongoing performance monitoring
- Implement automated validation procedures for continuous quality assurance
- Document all operational procedures and maintain comprehensive records
- Conduct periodic reviews to identify optimization opportunities
Quality Assurance:
- Validate all module interactions against established standards
- Ensure consistent application of best practices across all development phases
- Maintain documentation of all configuration changes and their impacts
Deployment Considerations
Operational Readiness:
- Verify all system components are properly configured before deployment
- Establish clear communication channels for ongoing support and maintenance
- Define escalation procedures for addressing operational challenges
Performance Optimization:
- Monitor system performance metrics to identify potential improvement areas
- Implement proactive measures to maintain optimal operational efficiency
- Regularly review and update operational procedures based on performance data
Knowledge Management
Information Governance:
- Maintain comprehensive documentation of all system components and processes
- Establish knowledge repositories for easy access to operational information
- Implement systematic approaches for knowledge sharing and continuous improvement
Continuous Improvement:
- Foster a culture of ongoing learning and adaptation within the operational framework
- Encourage feedback mechanisms to capture insights from all stakeholders
- Regularly assess and refine operational strategies to maximize effectiveness
Examples
Example 1: Account Creation
// Initialize a new resource account for protocol operations
let (resource_signer, signer_cap) = account::create_resource_account(
deployer,
b"PROTOCOL_ACCOUNT"
);
// Store the signer capability for future use
move_to(&resource_signer, Data {
signer_cap,
metadata: "Protocol Operations"
});
Example 2: Event Emission
// Emit a transfer event with comprehensive metadata
let transfer_event = TransferEvent {
from: account_address,
to: recipient_address,
amount: 1000,
};
event::emit(transfer_event);
Example 3: Time-Locked Withdrawal
// Execute a time-locked withdrawal operation
let current_time = timestamp::now_seconds();
let unlock_time = current_time + 86400; // 24 hours
assert!(current_time >= unlock_time, ERROR_LOCKED);
Example 4: Aggregator Statistics
// Track and aggregate operational metrics
let stats = Stats {
total: aggregator_v2::create_aggregator(0),
};
aggregator_v2::add(&mut stats.total, 1);
let current_value = aggregator_v2::read(&stats.total);
Note: This skill operates under a safety-first approach, ensuring all interactions maintain data integrity and service quality throughout the operational lifecycle.