scaffold-project
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseScaffold Project Skill
项目脚手架搭建Skill
Overview
概述
This skill creates new Aptos dApp projects by bootstrapping directly from official templates using . This
approach provides clean copies of production-ready templates without git history.
degit本Skill通过直接从官方模板引导创建新的Aptos dApp项目。这种方式可以获取生产就绪模板的干净副本,且不包含Git历史记录。
degitProject Types
项目类型
| Type | Template | Use Case |
|---|---|---|
| Fullstack dApp | | Frontend + smart contracts |
| Contract-only | | Smart contracts without frontend |
| 类型 | 模板名称 | 使用场景 |
|---|---|---|
| 全栈dApp | | 前端+智能合约 |
| 仅合约 | | 不含前端的智能合约 |
Fullstack dApp Scaffolding
全栈dApp搭建步骤
Step 1: Bootstrap with degit
步骤1:使用degit引导
bash
undefinedbash
undefinedBootstrap fullstack template (no git history)
引导全栈模板(无Git历史)
npx degit aptos-labs/create-aptos-dapp/templates/boilerplate-template my-dapp
cd my-dapp
> **Note:** The degit command references a specific template path in the aptos-labs/create-aptos-dapp repository. If you
> encounter errors, verify the template path exists at
> https://github.com/aptos-labs/create-aptos-dapp/tree/main/templatesnpx degit aptos-labs/create-aptos-dapp/templates/boilerplate-template my-dapp
cd my-dapp
> **注意:** degit命令引用了aptos-labs/create-aptos-dapp仓库中的特定模板路径。如果遇到错误,请验证模板路径是否存在于https://github.com/aptos-labs/create-aptos-dapp/tree/main/templatesStep 2: Configure Environment
步骤2:配置环境
Create file with the following variables:
.envbash
undefined创建文件并添加以下变量:
.envbash
undefinedCreate .env file
创建.env文件
cat > .env << 'EOF'
PROJECT_NAME=my-dapp
VITE_APP_NETWORK=devnet
VITE_APTOS_API_KEY=""
VITE_MODULE_PUBLISHER_ACCOUNT_ADDRESS=
cat > .env << 'EOF'
PROJECT_NAME=my-dapp
VITE_APP_NETWORK=devnet
VITE_APTOS_API_KEY=""
VITE_MODULE_PUBLISHER_ACCOUNT_ADDRESS=
This is the module publisher account's private key.
这是模块发布者账户的私钥。
Be cautious about who you share it with, and ensure it is not exposed when deploying your dApp.
请谨慎分享,确保在部署dApp时不会泄露。
VITE_MODULE_PUBLISHER_ACCOUNT_PRIVATE_KEY=
EOF
**Configure the values:**
- `PROJECT_NAME` - Your project name
- `VITE_APP_NETWORK` - Network to use (`devnet`, `testnet`, or `mainnet`)
- `VITE_APTOS_API_KEY` - Optional API key from Aptos Labs
- `VITE_MODULE_PUBLISHER_ACCOUNT_ADDRESS` - Your deployer account address (set after `aptos init`)
- `VITE_MODULE_PUBLISHER_ACCOUNT_PRIVATE_KEY` - Your deployer private key (from `~/.aptos/config.yaml`)
**⚠️ CRITICAL: Ensure `.env` is in `.gitignore`:**
```bashVITE_MODULE_PUBLISHER_ACCOUNT_PRIVATE_KEY=
EOF
**配置变量值:**
- `PROJECT_NAME` - 你的项目名称
- `VITE_APP_NETWORK` - 使用的网络(`devnet`、`testnet`或`mainnet`)
- `VITE_APTOS_API_KEY` - 可选的Aptos Labs提供的API密钥
- `VITE_MODULE_PUBLISHER_ACCOUNT_ADDRESS` - 你的部署者账户地址(执行`aptos init`后设置)
- `VITE_MODULE_PUBLISHER_ACCOUNT_PRIVATE_KEY` - 你的部署者私钥(来自`~/.aptos/config.yaml`)
**⚠️ 重要:确保`.env`已添加到`.gitignore`中:**
```bashVerify .env is gitignored (should already be there)
验证.env是否已被Git忽略(应该已存在)
grep -q "^.env$" .gitignore || echo ".env" >> .gitignore
undefinedgrep -q "^.env$" .gitignore || echo ".env" >> .gitignore
undefinedStep 3: Update Move.toml
步骤3:更新Move.toml
Edit with your project name:
contract/Move.tomltoml
[package]
name = "my_dapp" # Your project name
version = "1.0.0"
authors = []
[addresses]
my_dapp_addr = "_" # Will be set during deployment
[dev-addresses]
my_dapp_addr = "0xCAFE" # For testing
[dependencies]
AptosFramework = { git = "https://github.com/aptos-labs/aptos-framework.git", rev = "mainnet", subdir = "aptos-framework" }编辑,填入你的项目名称:
contract/Move.tomltoml
[package]
name = "my_dapp" # 你的项目名称
version = "1.0.0"
authors = []
[addresses]
my_dapp_addr = "_" # 将在部署时设置
[dev-addresses]
my_dapp_addr = "0xCAFE" # 用于测试
[dependencies]
AptosFramework = { git = "https://github.com/aptos-labs/aptos-framework.git", rev = "mainnet", subdir = "aptos-framework" }Step 4: Install Dependencies
步骤4:安装依赖
bash
npm installbash
npm installStep 5: Initialize Git
步骤5:初始化Git
bash
git init
git add .
git commit -m "Initial commit: Bootstrap Aptos dApp from boilerplate template"bash
git init
git add .
git commit -m "Initial commit: Bootstrap Aptos dApp from boilerplate template"Step 6: Verify Setup
步骤6:验证配置
bash
undefinedbash
undefinedCompile Move contracts
编译Move合约
npm run move:compile
npm run move:compile
Run Move tests
运行Move测试
npm run move:test
npm run move:test
Start frontend development server
启动前端开发服务器
npm run dev
undefinednpm run dev
undefinedFullstack Project Structure
全栈项目结构
my-dapp/
├── frontend/
│ ├── components/ # React UI components
│ ├── entry-functions/ # Write operations (transactions)
│ ├── view-functions/ # Read operations (queries)
│ ├── lib/ # Shared libraries (wallet, aptos client)
│ ├── utils/ # Helpers
│ ├── App.tsx
│ ├── constants.ts
│ └── main.tsx
├── contract/
│ ├── sources/ # Move modules
│ ├── tests/ # Move tests
│ └── Move.toml
├── scripts/move/ # Deployment scripts
├── package.json # npm scripts for move:compile, move:test, etc.
├── .env # Environment variables (NEVER commit!)
├── .gitignore # Must include .env
└── [config files] # vite, tailwind, typescript, etc.my-dapp/
├── frontend/
│ ├── components/ # React UI组件
│ ├── entry-functions/ # 写入操作(交易)
│ ├── view-functions/ # 读取操作(查询)
│ ├── lib/ # 共享库(钱包、Aptos客户端)
│ ├── utils/ # 工具函数
│ ├── App.tsx
│ ├── constants.ts
│ └── main.tsx
├── contract/
│ ├── sources/ # Move模块
│ ├── tests/ # Move测试
│ └── Move.toml
├── scripts/move/ # 部署脚本
├── package.json # npm脚本,如move:compile、move:test等
├── .env # 环境变量(绝对不要提交!)
├── .gitignore # 必须包含.env
└── [配置文件] # vite、tailwind、typescript等Key Directories Explained
关键目录说明
| Directory | Purpose |
|---|---|
| Transaction payloads for write operations |
| Queries for read operations |
| Aptos client and wallet provider setup |
| Move smart contract modules |
| Deployment and utility scripts |
| 目录 | 用途 |
|---|---|
| 写入操作的交易负载 |
| 读取操作的查询 |
| Aptos客户端和钱包提供者配置 |
| Move智能合约模块 |
| 部署和实用脚本 |
Contract-Only Scaffolding
仅合约项目搭建步骤
Step 1: Bootstrap with degit
步骤1:使用degit引导
bash
undefinedbash
undefinedBootstrap contract-only template
引导仅合约模板
npx degit aptos-labs/create-aptos-dapp/templates/contract-boilerplate-template my-contract
cd my-contract
undefinednpx degit aptos-labs/create-aptos-dapp/templates/contract-boilerplate-template my-contract
cd my-contract
undefinedStep 2: Configure Environment
步骤2:配置环境
Create file with the following variables:
.envbash
undefined创建文件并添加以下变量:
.envbash
undefinedCreate .env file
创建.env文件
cat > .env << 'EOF'
PROJECT_NAME=my-contract
VITE_APP_NETWORK=devnet
VITE_APTOS_API_KEY=""
VITE_MODULE_PUBLISHER_ACCOUNT_ADDRESS=
cat > .env << 'EOF'
PROJECT_NAME=my-contract
VITE_APP_NETWORK=devnet
VITE_APTOS_API_KEY=""
VITE_MODULE_PUBLISHER_ACCOUNT_ADDRESS=
This is the module publisher account's private key.
这是模块发布者账户的私钥。
Be cautious about who you share it with, and ensure it is not exposed when deploying your dApp.
请谨慎分享,确保在部署dApp时不会泄露。
VITE_MODULE_PUBLISHER_ACCOUNT_PRIVATE_KEY=
EOF
VITE_MODULE_PUBLISHER_ACCOUNT_PRIVATE_KEY=
EOF
Ensure .env is gitignored
确保.env已被Git忽略
grep -q "^.env$" .gitignore || echo ".env" >> .gitignore
undefinedgrep -q "^.env$" .gitignore || echo ".env" >> .gitignore
undefinedStep 3: Update Move.toml
步骤3:更新Move.toml
Edit :
contract/Move.tomltoml
[package]
name = "my_contract"
version = "1.0.0"
[addresses]
my_contract_addr = "_"
[dev-addresses]
my_contract_addr = "0xCAFE"
[dependencies]
AptosFramework = { git = "https://github.com/aptos-labs/aptos-framework.git", rev = "mainnet", subdir = "aptos-framework" }编辑:
contract/Move.tomltoml
[package]
name = "my_contract"
version = "1.0.0"
[addresses]
my_contract_addr = "_"
[dev-addresses]
my_contract_addr = "0xCAFE"
[dependencies]
AptosFramework = { git = "https://github.com/aptos-labs/aptos-framework.git", rev = "mainnet", subdir = "aptos-framework" }Step 4: Install & Verify
步骤4:安装依赖并验证
bash
npm installbash
npm installCompile
编译
npm run move:compile
npm run move:compile
Test
测试
npm run move:test
undefinednpm run move:test
undefinedStep 5: Initialize Git
步骤5:初始化Git
bash
git init
git add .
git commit -m "Initial commit: Bootstrap Aptos contract from template"bash
git init
git add .
git commit -m "Initial commit: Bootstrap Aptos contract from template"Contract-Only Project Structure
仅合约项目结构
my-contract/
├── contract/
│ ├── sources/ # Move modules
│ ├── tests/ # Move tests
│ └── Move.toml
├── scripts/move/ # Deployment scripts
├── package.json # npm scripts
├── .env # Environment variables (NEVER commit!)
└── .gitignore # Must include .envmy-contract/
├── contract/
│ ├── sources/ # Move模块
│ ├── tests/ # Move测试
│ └── Move.toml
├── scripts/move/ # 部署脚本
├── package.json # npm脚本
├── .env # 环境变量(绝对不要提交!)
└── .gitignore # 必须包含.envAvailable npm Scripts
可用的npm脚本
Both templates include these npm scripts:
bash
undefined两个模板都包含以下npm脚本:
bash
undefinedMove development
Move开发
npm run move:compile # Compile Move contracts
npm run move:test # Run Move tests
npm run move:publish # Publish to network (uses .env)
npm run move:compile # 编译Move合约
npm run move:test # 运行Move测试
npm run move:publish # 发布到网络(使用.env中的配置)
Fullstack only
仅全栈项目可用
npm run dev # Start frontend dev server
npm run build # Build for production
---npm run dev # 启动前端开发服务器
npm run build # 生产环境构建
---Alternative: Manual Move-Only Setup
替代方案:手动搭建仅Move项目
For pure Move development without the npm wrapper, use :
aptos move initbash
undefined如果不需要npm包装器,仅进行纯Move开发,可以使用:
aptos move initbash
undefinedInitialize Move project
初始化Move项目
aptos move init --name my_module
aptos move init --name my_module
Configure Move.toml manually
手动配置Move.toml
Create sources/ and tests/ directories
创建sources/和tests/目录
See the "Move-Only Reference" section below for detailed manual setup.
---
请查看下方的“仅Move参考”部分获取详细的手动配置步骤。
---Quick Reference Commands
快速参考命令
Fullstack dApp (Recommended)
全栈dApp(推荐)
bash
undefinedbash
undefinedBootstrap and setup
引导并配置
npx degit aptos-labs/create-aptos-dapp/templates/boilerplate-template my-dapp
cd my-dapp
npm install
git init
npx degit aptos-labs/create-aptos-dapp/templates/boilerplate-template my-dapp
cd my-dapp
npm install
git init
Then create .env manually (see Step 2 above) - NEVER commit .env!
然后手动创建.env文件(参考步骤2)——绝对不要提交.env!
undefinedundefinedContract-Only
仅合约项目
bash
undefinedbash
undefinedBootstrap and setup
引导并配置
npx degit aptos-labs/create-aptos-dapp/templates/contract-boilerplate-template my-contract
cd my-contract
npm install
git init
npx degit aptos-labs/create-aptos-dapp/templates/contract-boilerplate-template my-contract
cd my-contract
npm install
git init
Then create .env manually (see Step 2 above) - NEVER commit .env!
然后手动创建.env文件(参考步骤2)——绝对不要提交.env!
---
---Post-Scaffolding Checklist
搭建后检查清单
After bootstrapping, complete these steps:
- Create file with required variables (see Step 2)
.env - Verify is in
.env.gitignore - Update with project name and address alias
Move.toml - Run to create deployer account
aptos init - Add account address and private key to
.env - Verify compilation:
npm run move:compile - Verify tests pass:
npm run move:test - Initialize git repository
- (Fullstack) Verify frontend runs:
npm run dev
⚠️ Before committing: Double-check that is NOT staged ()
.envgit status完成引导后,请完成以下步骤:
- 创建包含所需变量的文件(参考步骤2)
.env - 验证已添加到
.env中.gitignore - 更新,填入项目名称和地址别名
Move.toml - 执行创建部署者账户
aptos init - 将账户地址和私钥添加到中
.env - 验证编译:
npm run move:compile - 验证测试通过:
npm run move:test - 初始化Git仓库
- (全栈项目)验证前端可正常运行:
npm run dev
⚠️ 提交前: 务必检查未被加入暂存区(使用)
.envgit statusMove-Only Reference (Manual Setup)
仅Move参考(手动配置)
For cases where you need manual Move setup without templates:
如果需要不使用模板的手动Move配置:
Initialize
初始化
bash
aptos move init --name my_modulebash
aptos move init --name my_moduleConfigure Move.toml
配置Move.toml
toml
[package]
name = "my_module"
version = "1.0.0"
[addresses]
my_addr = "_"
[dev-addresses]
my_addr = "0xCAFE"
[dependencies]
AptosFramework = { git = "https://github.com/aptos-labs/aptos-framework.git", rev = "mainnet", subdir = "aptos-framework" }toml
[package]
name = "my_module"
version = "1.0.0"
[addresses]
my_addr = "_"
[dev-addresses]
my_addr = "0xCAFE"
[dependencies]
AptosFramework = { git = "https://github.com/aptos-labs/aptos-framework.git", rev = "mainnet", subdir = "aptos-framework" }Create Module
创建模块
move
// sources/main.move
module my_addr::main {
use std::signer;
struct Counter has key {
value: u64
}
public entry fun init_counter(account: &signer) {
move_to(account, Counter { value: 0 });
}
public entry fun increment(account: &signer) acquires Counter {
let counter = borrow_global_mut<Counter>(signer::address_of(account));
counter.value = counter.value + 1;
}
}move
// sources/main.move
module my_addr::main {
use std::signer;
struct Counter has key {
value: u64
}
public entry fun init_counter(account: &signer) {
move_to(account, Counter { value: 0 });
}
public entry fun increment(account: &signer) acquires Counter {
let counter = borrow_global_mut<Counter>(signer::address_of(account));
counter.value = counter.value + 1;
}
}Verify
验证
bash
aptos move compile
aptos move testbash
aptos move compile
aptos move testALWAYS Rules
必须遵守的规则
- ✅ ALWAYS use for bootstrapping (clean copy, no git history)
degit - ✅ ALWAYS use the boilerplate-template for fullstack dApps
- ✅ ALWAYS update Move.toml with your project name and address alias
- ✅ ALWAYS create file with required environment variables
.env - ✅ ALWAYS ensure is listed in
.env.gitignore - ✅ ALWAYS run after bootstrapping
npm install - ✅ ALWAYS verify compilation and tests pass
- ✅ ALWAYS initialize git after setup
- ✅ ALWAYS use named addresses (myaddr = "")
- ✅ 必须使用进行引导(干净副本,无Git历史)
degit - ✅ 全栈dApp必须使用boilerplate-template模板
- ✅ 必须更新Move.toml,填入项目名称和地址别名
- ✅ 必须创建包含所需环境变量的文件
.env - ✅ 必须确保已添加到
.env中.gitignore - ✅ 引导完成后必须执行
npm install - ✅ 必须验证编译和测试通过
- ✅ 配置完成后必须初始化Git
- ✅ 必须使用命名地址(如my_addr = "_")
NEVER Rules
绝对禁止的操作
- ❌ NEVER commit to git (contains private keys!)
.env - ❌ NEVER push to GitHub or any remote repository
.env - ❌ NEVER share your
VITE_MODULE_PUBLISHER_ACCOUNT_PRIVATE_KEY - ❌ NEVER skip Move.toml configuration
- ❌ NEVER use hardcoded addresses in code
- ❌ NEVER skip verifying compilation after scaffolding
- ❌ NEVER read files after creation — to verify existence, use
.envnotls -la .envcat .env - ❌ NEVER display values in responses
VITE_MODULE_PUBLISHER_ACCOUNT_PRIVATE_KEY - ❌ NEVER run or
git add .untilgit add -Acontains.gitignore— always verify first.env
- ❌ 绝对不要将提交到Git(包含私钥!)
.env - ❌ 绝对不要将推送到GitHub或任何远程仓库
.env - ❌ 绝对不要分享你的
VITE_MODULE_PUBLISHER_ACCOUNT_PRIVATE_KEY - ❌ 绝对不要跳过Move.toml的配置
- ❌ 绝对不要在代码中使用硬编码地址
- ❌ 绝对不要跳过搭建后的编译验证
- ❌ 绝对不要在创建后查看文件内容——如需验证文件存在,使用
.env而非ls -la .envcat .env - ❌ 绝对不要在回复中显示的值
VITE_MODULE_PUBLISHER_ACCOUNT_PRIVATE_KEY - ❌ 绝对不要在包含
.gitignore前执行.env或git add .——务必先验证git add -A
Template Sources
模板来源
References
参考资料
Official Documentation:
- CLI Reference: https://aptos.dev/build/cli
- Move.toml: https://aptos.dev/build/cli/working-with-move-contracts
- TypeScript SDK: https://aptos.dev/sdks/ts-sdk
Related Skills:
- - Write Move modules after scaffolding
write-contracts - - Create test suite
generate-tests - - Wire up frontend to contracts
connect-contract-to-frontend - - Add wallet connection
integrate-wallet-adapter
Remember: Use for clean bootstrapping. The boilerplate template provides the best starting point for custom
dApps.
degit官方文档:
- CLI参考:https://aptos.dev/build/cli
- Move.toml:https://aptos.dev/build/cli/working-with-move-contracts
- TypeScript SDK:https://aptos.dev/sdks/ts-sdk
相关Skill:
- - 搭建完成后编写Move模块
write-contracts - - 创建测试套件
generate-tests - - 将前端与合约关联
connect-contract-to-frontend - - 添加钱包连接功能
integrate-wallet-adapter
提示: 使用进行干净的项目引导。boilerplate-template是自定义dApp的最佳起点。
degit