aptos-move-language

$npx mdskill add eric861129/SKILLS_All-in-one/aptos-move-language

Provides expert guidance on Move language fundamentals for Aptos blockchain development.

  • Helps developers understand Move's type system and resource-oriented programming.
  • Relies on Move compiler, Aptos framework, and standard library documentation.
  • Analyzes code patterns and constraints to recommend correct usage of abilities and generics.
  • Delivers explanations, code examples, and best practices for writing safe Move code.

SKILL.md

.github/skills/aptos-move-languageView on GitHub ↗
---
name: aptos-move-language
description: Expert on Move programming language fundamentals including abilities (copy/drop/store/key), generics, phantom types, references, global storage operations (move_to/move_from/borrow_global), signer pattern, visibility modifiers, and advanced type system features.
allowed-tools: Read, Write, Edit, Grep, Glob, Bash
model: sonnet
license: MIT
metadata:
  author: raintree
  version: "1.0"
---

# Move Language Expert

Deep expertise on the Move programming language for Aptos blockchain.

## Triggers

- move language, abilities, generics
- phantom type, borrow_global
- signer, friend, inline
- copy, drop, store, key
- move_to, move_from, acquires

## Abilities

The four abilities control what can be done with types:

| Ability | Meaning | Use Case |
|---------|---------|----------|
| `copy` | Can be copied | Primitives, configs |
| `drop` | Can be discarded | Temporary data |
| `store` | Can be stored in structs | Most data types |
| `key` | Can be top-level resource | Account resources |

```move
struct Resource has key, store { value: u64 }
struct Point has copy, drop, store { x: u64, y: u64 }
struct Capability {}  // No abilities - hot potato
```

### Critical Rules

1. Fields must have compatible abilities
2. Structs without `drop` must be explicitly handled
3. `copy` requires all fields to have `copy`

## Generics

```move
struct Box<T: store> has store {
    value: T
}

public fun create<T: store>(value: T): Box<T> {
    Box { value }
}
```

### Phantom Types (Zero-Cost Type Safety)

```move
struct Coin<phantom CoinType> has store {
    value: u64  // CoinType doesn't appear here
}

struct BTC {}
struct ETH {}

// Coin<BTC> != Coin<ETH> at compile time
```

## References

```move
// Immutable reference
fun read(x: &u64): u64 { *x }

// Mutable reference
fun increment(x: &mut u64) { *x = *x + 1; }
```

### Reference Rules

- Can't have mutable + immutable refs simultaneously
- Only one mutable reference at a time
- References can't outlive values

## Global Storage

```move
// Store resource
move_to(account, MyResource { value: 0 });

// Remove resource
let resource = move_from<MyResource>(addr);

// Immutable borrow
let r = borrow_global<MyResource>(addr);

// Mutable borrow
let r = borrow_global_mut<MyResource>(addr);

// Check existence
exists<MyResource>(addr);
```

### The `acquires` Annotation

```move
public fun get_value(addr: address): u64 acquires MyResource {
    borrow_global<MyResource>(addr).value
}
```

## Signer

`signer` is Move's authentication primitive:

```move
public entry fun initialize(account: &signer) {
    move_to(account, Resource { value: 0 });
}

let addr = signer::address_of(account);
```

## Visibility

```move
fun private_fn() { }                    // Module only
public fun public_fn() { }              // Anywhere
public(friend) fun friend_fn() { }      // Friends only
public entry fun entry_fn(s: &signer) { }  // Transaction entry
entry fun local_entry(s: &signer) { }   // Local entry
```

### Friend Declarations

```move
module admin {
    friend user_module;
    public(friend) fun admin_function() { }
}
```

## Inline Functions

```move
inline fun min(a: u64, b: u64): u64 {
    if (a < b) a else b
}
```

## Common Patterns

### Capability Pattern

```move
struct AdminCap has key, store {}

public fun admin_only(admin: &signer) acquires AdminCap {
    assert!(exists<AdminCap>(signer::address_of(admin)), ERROR);
}
```

### Witness Pattern

```move
struct MyModule has drop {}

public fun initialize<T: drop>(account: &signer, _witness: T) {
    move_to(account, Config<T> { });
}
```

### Hot Potato Pattern

```move
struct Receipt { amount: u64 }  // No abilities!

public fun buy(): Receipt { Receipt { amount: 100 } }
public fun redeem(r: Receipt) { let Receipt { amount } = r; }
// Must call both - can't drop Receipt
```

## Best Practices

- Use abilities explicitly
- Leverage phantom types for type safety
- Constrain generics only as needed
- Use references to avoid copies
- Check exists before borrow_global
- Always annotate acquires

More from eric861129/SKILLS_All-in-one

SkillDescription
agnixUse when user asks to 'lint agent configs', 'validate skills', 'check CLAUDE.md', 'validate hooks', 'lint MCP'. Validates agent configuration files against 231 rules across 10+ AI tools.
anthropic-expertExpert on Anthropic Claude API, models, prompt engineering, function calling, vision, and best practices. Triggers on anthropic, claude, api, prompt, function calling, vision, messages api, embeddings
aptos-cliExpert in Aptos CLI for account management, contract deployment, transaction submission, and node operations. Use when using the Aptos CLI to initialize profiles, deploy Move contracts, submit transactions, manage accounts, or operate Aptos nodes.
aptos-coreExpert in Aptos blockchain core architecture: consensus (AptosBFT), execution (Block-STM), and networking. Use when analyzing Aptos protocol design, the Rust codebase, validator operations, or understanding how Block-STM parallel execution works.
aptos-dapp-integrationExpert on building Aptos dApps with frontend integration. Covers wallet connectivity (Petra, Martian, Pontem), wallet adapter patterns, TypeScript SDK, transaction building and submission, account management, and React/Next.js integration.
aptos-frameworkExpert on Aptos Framework (0x1 standard library) modules including account, coin, fungible_asset, object, timestamp, table, smart_table, event, randomness, aggregator, and resource_account. Essential for all Aptos development.
aptos-gas-optimizationAptos gas optimization expert for Move smart contracts. Covers storage costs, execution efficiency, inline functions, aggregators for parallel execution, Table vs SmartTable vs vector tradeoffs, event optimization, struct packing, and gas profiling tools.
aptos-indexerExpert in Aptos Indexer architecture and GraphQL API for querying blockchain data. Use when querying NFTs, coin balances, or transaction history via GraphQL, designing custom processors, or optimizing data retrieval from the Aptos blockchain.
aptos-move-testingExpert on testing Move smart contracts including unit tests, integration tests, Move Prover formal verification, debugging strategies, test coverage, and CI/CD integration for Aptos development.
aptos-object-modelExpert on Aptos Object Model for composable, transferable on-chain assets. Use when working with ObjectCore, Object wrappers, ConstructorRef, ExtendRef, DeleteRef, TransferRef capabilities, or implementing composable asset patterns on Aptos blockchain.