Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit f3b52ca

Browse files
committed
Add Chinese documentation for various smart contract topics
- Introduced new pages covering cryptography, debugging, deployment, digital assets, error codes, fungible assets, linter, maps, modules, randomness, resource accounts, scripts, smart vectors, tables, third-party dependencies, tokens, and vectors. - Enhanced the structure and organization of the documentation to improve clarity and accessibility for developers. - Provided comprehensive guides and examples to facilitate understanding and usage of the Move programming language on the Aptos platform.
1 parent ded9ac3 commit f3b52ca

23 files changed

+4137
-0
lines changed

apps/nextra/pages/zh/build/smart-contracts/cryptography.mdx

Lines changed: 247 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
title: "调试 Move"
3+
---
4+
5+
# 调试 Move
6+
7+
Move 设计得简单且安全,但与所有编程语言一样,仍然可能出现错误。本指南将帮助您调试 Move 代码并找出问题所在。
8+
9+
请随时贡献额外的工具和信息,以帮助社区中的其他人。
10+
11+
## 使用 Aptos CLI 进行调试
12+
13+
### 交易提交时的模拟
14+
15+
您可以使用 Aptos CLI 在执行之前模拟入口函数。
16+
17+
通常,如果交易在链上无法执行,模拟时也会失败。例如:
18+
19+
```bash name="Terminal"
20+
aptos move run --function-id 0x1::aptos_account::transfer --args address:0x1 u64:1000000000000000000
21+
{
22+
"Error": "Simulation failed with status: Move abort in 0x1::coin: EINSUFFICIENT_BALANCE(0x10006): Not enough coins to complete transaction"
23+
}
24+
```
25+
26+
同样适用于 Move 脚本。例如:
27+
28+
```bash name="Terminal"
29+
aptos move run-script --script-path <script_path> ...
30+
```
31+
32+
### 本地模拟
33+
34+
此外,在某些情况下,本地模拟可能会提供额外的信息,并[打印出您代码中的任何调试语句](https://aptos.dev/en/build/cli/working-with-move-contracts#printing-debugging-information)
35+
36+
```bash name="Terminal"
37+
aptos move run --function-id 0x1::aptos_account::transferred --args address:0x1 u64:1000000000000000000 --local
38+
39+
Simulating transaction locally...
40+
{
41+
"Result": {
42+
"transaction_hash": "0x4115316915d409ba4106632c82d4b09220035ffdbd0b86bbe29a586d03d06318",
43+
"gas_used": 3,
44+
"gas_unit_price": 100,
45+
"sender": "78077fe8db589e1a3407170cf8af3bd60a8c95737918c15dd6f49dcbecc7900a",
46+
"success": false,
47+
"version": 56634003,
48+
"vm_status": "status FUNCTION_RESOLUTION_FAILURE of type Verification with message Function 0x1::aptos_account::transferred does not exist"
49+
}
50+
}
51+
```
52+
53+
### Gas 分析和追踪
54+
55+
添加 gas 分析将额外提供计算中使用的 gas 量的追踪能力:
56+
57+
```bash name="Terminal"
58+
aptos move run --function-id 0x1::aptos_account::transferred --args address:0x1 u64:1000000000000000000 --profile-gas
59+
60+
Simulating transaction locally using the gas profiler...
61+
Gas report saved to gas-profiling/txn-a90ca655-0x1-aptos_account-transferred.
62+
{
63+
"Result": {
64+
"transaction_hash": "0xa90ca6550dcdd7f514f4cdcdee7dc1fbee17082fcf68f3db3e5755a93b89bcfc",
65+
"gas_used": 3,
66+
"gas_unit_price": 100,
67+
"sender": "78077fe8db589e1a3407170cf8af3bd60a8c95737918c15dd6f49dcbecc7900a",
68+
"success": false,
69+
"version": 56651618,
70+
"vm_status": "status FUNCTION_RESOLUTION_FAILURE of type Verification with message Function 0x1::aptos_account::transferred does not exist"
71+
}
72+
}
73+
```
74+
75+
这将生成一个可在 HTML 格式中查看的 gas 报告:
76+
77+
```bash name="Terminal"
78+
open gas-profiling/txn-a90ca655-0x1-aptos_account-transferred/index.html
79+
```
80+
81+
## 评估性能
82+
83+
```bash name="Terminal"
84+
aptos move run --function-id 0x1::aptos_account::transfer --args address:0x1 u64:1 --benchmark
85+
86+
Benchmarking transaction locally...
87+
Running time (cold code cache): 22.144458ms
88+
Running time (warm code cache): 669.5µs
89+
{
90+
"Result": {
91+
"transaction_hash": "0x7cdf37ff4d798b3ac3f1e860a40428853e381598a511b9291f2a49e5ff6262a0",
92+
"gas_used": 11,
93+
"gas_unit_price": 100,
94+
"sender": "78077fe8db589e1a3407170cf8af3bd60a8c95737918c15dd6f49dcbecc7900a",
95+
"success": true,
96+
"version": 56679764,
97+
"vm_status": "status EXECUTED of type Execution"
98+
}
99+
}
100+
```
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
---
2+
title: "对象代码部署"
3+
---
4+
5+
# 对象代码部署
6+
7+
本文档介绍如何将代码部署到 [Objects](objects.mdx)。这是将代码部署到区块链的推荐方式,因为这减少了部署的复杂性,并安全地管理代码所有者的访问控制策略。请注意,在此上下文中,代码是指 [packages](book/packages.mdx)
8+
9+
将代码部署到对象将保证以下几点:
10+
- 每次部署发布到一个新地址。
11+
- 只有**代码对象的所有者**可以升级和冻结代码。
12+
13+
这意味着您可以将对象转移给新所有者,他们将拥有代码的完整所有权。您正在授予他们升级和冻结代码的权利。无需管理种子,或在每次部署时部署到新地址。对象代码部署极大地简化了部署过程。
14+
15+
## 指南
16+
17+
以下是如何编译、部署和升级代码到对象的说明。
18+
19+
import { Steps } from 'nextra/components'
20+
21+
<Steps>
22+
23+
### 编译代码
24+
25+
确保 `<named_address>` 保持为占位符 `_`。这是必需的,因为 CLI 命令将覆盖地址。`<named_address>` 值表示代码的所有者,或要将代码部署到的对象的所有者。
26+
以下是 `<named_address>` 值为 `my_address` 的示例。
27+
28+
```toml filename="Move.toml"
29+
[addresses]
30+
my_address = "_"
31+
```
32+
33+
通过运行以下命令编译您的 move 代码。
34+
-`<named_address>` 替换为命名地址。
35+
-`<your_address>` 替换为您的账户地址。
36+
37+
```bash filename="Terminal"
38+
aptos move compile --named-addresses <named_address>=<your_address>
39+
```
40+
41+
### 将代码部署到对象
42+
43+
通过以下命令将编译后的代码部署到对象:
44+
-`<named_address>` 替换为命名地址。
45+
46+
```bash filename="Terminal"
47+
aptos move deploy-object --address-name <named_address>
48+
```
49+
50+
**下面是一个示例:**
51+
52+
```bash filename="Terminal"
53+
aptos move deploy-object --address-name my_address
54+
```
55+
56+
这将询问您是否要在指定的对象地址下发布代码。
57+
58+
**示例输出:**
59+
60+
```bash filename="Terminal"
61+
Do you want to publish this package at object address 0x8d6eb306bcf6c61dbaa0dbf8daa8252e121b63e95991afcab3b12d3be7f001ab [yes/no] >
62+
```
63+
64+
**恭喜,您已将代码部署到具有唯一地址的新对象!**
65+
66+
请注意对象地址,因为您稍后需要它进行升级。
67+
68+
### 转移和升级现有包中的代码
69+
70+
首先,您可能希望将对象从部署者账户转移到管理员账户。管理员账户将有权升级代码。
71+
72+
以下是通过 CLI 的操作方法,这里您的 `deployer_account` 应该是对象的当前所有者。
73+
```bash
74+
aptos move run —-function-id 0x1::object::transfer --type-args 0x1::object::ObjectCore -—args address:<object_address> address:<new_owner_address> —-profile <deployer_account_profile>
75+
```
76+
77+
以下是通过 typescript SDK 的操作方法:
78+
```typescript
79+
const transaction = await aptos.transaction.build.simple({
80+
sender: deployerAccount.accountAddress,
81+
data: {
82+
function: "0x1::object::transfer",
83+
typeArguments: [`0x1::object::ObjectCore`],
84+
functionArguments: [object_address, new_owner_address],
85+
},
86+
});
87+
```
88+
现在,您可以使用指定的管理员账户升级代码,如下所示。
89+
90+
如果您希望升级已部署的对象中的代码,请运行以下命令:
91+
-`<named_address>` 替换为现有的命名地址。
92+
-`<code_object_addr>` 替换为托管代码的对象地址。
93+
94+
注意:账户名称的值现在应该是对象地址,因为包含模块的包现在已部署到该地址。
95+
96+
```bash filename="Terminal"
97+
aptos move upgrade-object --address-name <named_address> --object-address <code_object_addr>
98+
```
99+
100+
上述命令的示例:
101+
102+
```bash filename="Terminal"
103+
aptos move upgrade-object --address-name my_address --object-address 0x8d6eb306bcf6c61dbaa0dbf8daa8252e121b63e95991afcab3b12d3be7f001ab
104+
```
105+
106+
这将询问您是否要升级在对象地址上部署的现有代码。
107+
108+
**示例输出:**
109+
110+
```bash filename="Terminal"
111+
Do you want to upgrade the package 'MyPackage' at object address 0x8d6eb306bcf6c61dbaa0dbf8daa8252e121b63e95991afcab3b12d3be7f001ab [yes/no]
112+
```
113+
114+
**恭喜,您已在现有对象中升级了代码!**
115+
116+
</Steps>

0 commit comments

Comments
 (0)