Aptos Move Integration Guide
This guide covers integrating Aptos Move smart contracts with TypeScript frontends, including contract interaction patterns, resource management, event handling, and testing strategies for 2025.
Prerequisites
- Aptos CLI installed for Move development
- Understanding of Move language basics
- TypeScript/React knowledge for frontend integration
- @aptos-labs/ts-sdk for blockchain interactions
Move Contract Structure
Basic Move Module Example
// sources/counter.move
module my_address::counter {
use std::signer;
use aptos_framework::event;
struct Counter has key {
value: u64,
}
#[event]
struct CounterCreated has drop, store {
account: address,
initial_value: u64,
}
#[event]
struct CounterIncremented has drop, store {
account: address,
old_value: u64,
new_value: u64,
}
public entry fun initialize_counter(account: &signer) {
let account_addr = signer::address_of(account);
assert!(!exists<Counter>(account_addr), 1);
let counter = Counter { value: 0 };
move_to(account, counter);
event::emit(CounterCreated {
account: account_addr,
initial_value: 0,
});
}
public entry fun increment(account: &signer) acquires Counter {
let account_addr = signer::address_of(account);
let counter = borrow_global_mut<Counter>(account_addr);
let old_value = counter.value;
counter.value = counter.value + 1;
event::emit(CounterIncremented {
account: account_addr,
old_value,
new_value: counter.value,
});
}
#[view]
public fun get_value(account_addr: address): u64 acquires Counter {
borrow_global<Counter>(account_addr).value
}
public entry fun set_value(account: &signer, new_value: u64) acquires Counter {
let account_addr = signer::address_of(account);
let counter = borrow_global_mut<Counter>(account_addr);
counter.value = new_value;
}
}
Move.toml Configuration
[package]
name = "counter"
version = "1.0.0"
authors = ["your-email@example.com"]
[dependencies.AptosFramework]
git = "https://github.com/aptos-labs/aptos-core.git"
rev = "mainnet"
subdir = "aptos-move/framework/aptos-framework"
[addresses]
my_address = "_"