scaffold-project

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Scaffold Project Skill

项目脚手架搭建Skill

Overview

概述

This skill creates new Aptos dApp projects by bootstrapping directly from official templates using
degit
. This approach provides clean copies of production-ready templates without git history.
本Skill通过
degit
直接从官方模板引导创建新的Aptos dApp项目。这种方式可以获取生产就绪模板的干净副本,且不包含Git历史记录。

Project Types

项目类型

TypeTemplateUse Case
Fullstack dApp
boilerplate-template
Frontend + smart contracts
Contract-only
contract-boilerplate-template
Smart contracts without frontend

类型模板名称使用场景
全栈dApp
boilerplate-template
前端+智能合约
仅合约
contract-boilerplate-template
不含前端的智能合约

Fullstack dApp Scaffolding

全栈dApp搭建步骤

Step 1: Bootstrap with degit

步骤1:使用degit引导

bash
undefined
bash
undefined

Bootstrap 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/templates
npx 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/templates

Step 2: Configure Environment

步骤2:配置环境

Create
.env
file
with the following variables:
bash
undefined
创建
.env
文件
并添加以下变量:
bash
undefined

Create .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`:**

```bash
VITE_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`中:**

```bash

Verify .env is gitignored (should already be there)

验证.env是否已被Git忽略(应该已存在)

grep -q "^.env$" .gitignore || echo ".env" >> .gitignore
undefined
grep -q "^.env$" .gitignore || echo ".env" >> .gitignore
undefined

Step 3: Update Move.toml

步骤3:更新Move.toml

Edit
contract/Move.toml
with your project name:
toml
[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.toml
,填入你的项目名称:
toml
[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 install
bash
npm install

Step 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
undefined
bash
undefined

Compile 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
undefined
npm run dev
undefined

Fullstack 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

关键目录说明

DirectoryPurpose
frontend/entry-functions/
Transaction payloads for write operations
frontend/view-functions/
Queries for read operations
frontend/lib/
Aptos client and wallet provider setup
contract/sources/
Move smart contract modules
scripts/move/
Deployment and utility scripts

目录用途
frontend/entry-functions/
写入操作的交易负载
frontend/view-functions/
读取操作的查询
frontend/lib/
Aptos客户端和钱包提供者配置
contract/sources/
Move智能合约模块
scripts/move/
部署和实用脚本

Contract-Only Scaffolding

仅合约项目搭建步骤

Step 1: Bootstrap with degit

步骤1:使用degit引导

bash
undefined
bash
undefined

Bootstrap contract-only template

引导仅合约模板

npx degit aptos-labs/create-aptos-dapp/templates/contract-boilerplate-template my-contract
cd my-contract
undefined
npx degit aptos-labs/create-aptos-dapp/templates/contract-boilerplate-template my-contract
cd my-contract
undefined

Step 2: Configure Environment

步骤2:配置环境

Create
.env
file
with the following variables:
bash
undefined
创建
.env
文件
并添加以下变量:
bash
undefined

Create .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
undefined
grep -q "^.env$" .gitignore || echo ".env" >> .gitignore
undefined

Step 3: Update Move.toml

步骤3:更新Move.toml

Edit
contract/Move.toml
:
toml
[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.toml
toml
[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 install
bash
npm install

Compile

编译

npm run move:compile
npm run move:compile

Test

测试

npm run move:test
undefined
npm run move:test
undefined

Step 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 .env

my-contract/
├── contract/
│   ├── sources/              # Move模块
│   ├── tests/                # Move测试
│   └── Move.toml
├── scripts/move/             # 部署脚本
├── package.json              # npm脚本
├── .env                      # 环境变量(绝对不要提交!)
└── .gitignore                # 必须包含.env

Available npm Scripts

可用的npm脚本

Both templates include these npm scripts:
bash
undefined
两个模板都包含以下npm脚本:
bash
undefined

Move 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 init
:
bash
undefined
如果不需要npm包装器,仅进行纯Move开发,可以使用
aptos move init
bash
undefined

Initialize 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
undefined
bash
undefined

Bootstrap 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!

undefined
undefined

Contract-Only

仅合约项目

bash
undefined
bash
undefined

Bootstrap 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
    .env
    file with required variables (see Step 2)
  • Verify
    .env
    is in
    .gitignore
  • Update
    Move.toml
    with project name and address alias
  • Run
    aptos init
    to create deployer account
  • 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
.env
is NOT staged (
git status
)

完成引导后,请完成以下步骤:
  • 创建包含所需变量的
    .env
    文件(参考步骤2)
  • 验证
    .env
    已添加到
    .gitignore
  • 更新
    Move.toml
    ,填入项目名称和地址别名
  • 执行
    aptos init
    创建部署者账户
  • 将账户地址和私钥添加到
    .env
  • 验证编译:
    npm run move:compile
  • 验证测试通过:
    npm run move:test
  • 初始化Git仓库
  • (全栈项目)验证前端可正常运行:
    npm run dev
⚠️ 提交前: 务必检查
.env
未被加入暂存区(使用
git status

Move-Only Reference (Manual Setup)

仅Move参考(手动配置)

For cases where you need manual Move setup without templates:
如果需要不使用模板的手动Move配置:

Initialize

初始化

bash
aptos move init --name my_module
bash
aptos move init --name my_module

Configure 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 test

bash
aptos move compile
aptos move test

ALWAYS Rules

必须遵守的规则

  • ✅ ALWAYS use
    degit
    for bootstrapping (clean copy, no git history)
  • ✅ ALWAYS use the boilerplate-template for fullstack dApps
  • ✅ ALWAYS update Move.toml with your project name and address alias
  • ✅ ALWAYS create
    .env
    file with required environment variables
  • ✅ ALWAYS ensure
    .env
    is listed in
    .gitignore
  • ✅ ALWAYS run
    npm install
    after bootstrapping
  • ✅ ALWAYS verify compilation and tests pass
  • ✅ ALWAYS initialize git after setup
  • ✅ ALWAYS use named addresses (myaddr = "")
  • ✅ 必须使用
    degit
    进行引导(干净副本,无Git历史)
  • ✅ 全栈dApp必须使用boilerplate-template模板
  • ✅ 必须更新Move.toml,填入项目名称和地址别名
  • ✅ 必须创建包含所需环境变量的
    .env
    文件
  • ✅ 必须确保
    .env
    已添加到
    .gitignore
  • ✅ 引导完成后必须执行
    npm install
  • ✅ 必须验证编译和测试通过
  • ✅ 配置完成后必须初始化Git
  • ✅ 必须使用命名地址(如my_addr = "_")

NEVER Rules

绝对禁止的操作

  • ❌ NEVER commit
    .env
    to git (contains private keys!)
  • ❌ NEVER push
    .env
    to GitHub or any remote repository
  • ❌ 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
    .env
    files after creation — to verify existence, use
    ls -la .env
    not
    cat .env
  • ❌ NEVER display
    VITE_MODULE_PUBLISHER_ACCOUNT_PRIVATE_KEY
    values in responses
  • ❌ NEVER run
    git add .
    or
    git add -A
    until
    .gitignore
    contains
    .env
    — always verify first

  • ❌ 绝对不要将
    .env
    提交到Git(包含私钥!)
  • ❌ 绝对不要将
    .env
    推送到GitHub或任何远程仓库
  • ❌ 绝对不要分享你的
    VITE_MODULE_PUBLISHER_ACCOUNT_PRIVATE_KEY
  • ❌ 绝对不要跳过Move.toml的配置
  • ❌ 绝对不要在代码中使用硬编码地址
  • ❌ 绝对不要跳过搭建后的编译验证
  • ❌ 绝对不要在创建后查看
    .env
    文件内容——如需验证文件存在,使用
    ls -la .env
    而非
    cat .env
  • ❌ 绝对不要在回复中显示
    VITE_MODULE_PUBLISHER_ACCOUNT_PRIVATE_KEY
    的值
  • ❌ 绝对不要在
    .gitignore
    包含
    .env
    前执行
    git add .
    git add -A
    ——务必先验证

Template Sources

模板来源

References

参考资料

Official Documentation:
Related Skills:
  • write-contracts
    - Write Move modules after scaffolding
  • generate-tests
    - Create test suite
  • connect-contract-to-frontend
    - Wire up frontend to contracts
  • integrate-wallet-adapter
    - Add wallet connection

Remember: Use
degit
for clean bootstrapping. The boilerplate template provides the best starting point for custom dApps.
官方文档:
相关Skill:
  • write-contracts
    - 搭建完成后编写Move模块
  • generate-tests
    - 创建测试套件
  • connect-contract-to-frontend
    - 将前端与合约关联
  • integrate-wallet-adapter
    - 添加钱包连接功能

提示: 使用
degit
进行干净的项目引导。boilerplate-template是自定义dApp的最佳起点。