# 与 Aptos 区块链交互

Aptos 区块链使用 [Move](https://diem.github.io/move/) 虚拟机 (VM) 来执行操作。虽然许多区块链实现了一组原生操作，但 Aptos 将所有操作委托给 Move，包括：账户创建、资金转账和发布 Move 模块。为了支持这些操作，构建在 Move 之上的区块链必须提供一个框架（类似于计算机的操作系统或最小的可行功能集）来与区块链交互。在本节中，我们将讨论这些通过 Aptos 框架的 script 函数来发布。

本指南（与 [Move 模块教程](/jiao-cheng/nin-de-di-yi-ge-move-mo-kuai.md)一起）将解锁在 Aptos 区块链之上开始构建丰富应用程序所需的最少信息量。注意：Aptos 框架正在大力开发中，本文档可能不是最新的。最新的框架可以在[源代码](https://github.com/aptos-labs/aptos-core/tree/main/aptos-move/framework/aptos-framework/sources)中找到。

Aptos Framework 内提供给用户的核心功能包括：

* 发送和接收 `TestCoin`
* 创建新帐户
* 发布新的 Move 模块

注意：本文档假设读者已经熟悉提交交易，如[您的第一个交易教程](/jiao-cheng/nin-de-di-yi-bi-jiao-yi.md)中所述。

### 发送和接收 `TestCoin`[​](https://aptos.dev/transactions/interacting-with-the-aptos-blockchain#sending-and-receiving-testcoin) <a href="#sending-and-receiving-testcoin" id="sending-and-receiving-testcoin"></a>

提交和执行交易时需要 TestCoin 来支付gas费用。 TestCoin 可以通过查询 Devnet Faucet 获得。 有关示例，请参阅您的第一次交易教程。

执行转账的 payload 是：

```json
{
  "type": "script_function_payload",
  "function": "0x1::TestCoin::transfer",
  "type_arguments": [],
  "arguments": [
    "0x737b36c96926043794ed3a0b3eaaceaf",
    "1000",
  ]
}
```

这指示 VM 执行脚本 `script` `0x1::TestCoin::transfer`。第一个参数是发送方地址， `0x737b36c96926043794ed3a0b3eaaceaf`, 第二个是要转账的金额，`1000`。发送方地址是调用此 script 发送交易的账户地址。

### 创建新账户[​](https://aptos.dev/transactions/interacting-with-the-aptos-blockchain#creating-a-new-account) <a href="#creating-a-new-account" id="creating-a-new-account"></a>

创建新帐户的 payload 是：

```json
{
  "type": "script_function_payload",
  "function": "0x1::AptosAccount::create_account",
  "type_arguments": [],
  "arguments": [
    "0x0c7e09cd9185a27104fa218a0b26ea88",
    "0xaacf87ae9d8a5e523c7f1107c668cb28dec005933c4a3bf0465ffd8a9800a2d900",
  ]
}
```

这指示 Move 虚拟机执行 `script` `0x1::AptosAccount::create_account`。第一个参数是要创建的帐户的地址，第二个参数是身份验证密钥原像（在 Accounts 中提到）。对于单一签名者身份验证，这是与 0 字节（或 `pubkey_A | 0x00`）连接的公钥。 这是防止帐户地址抢占所必需的。 该指令的执行验证验证密钥的最后 16 字节是否与 16 字节的帐户地址相同。 我们正在积极努力改进此 API，以支持接收 32 字节的帐户地址，从而消除对抢占或帐户操纵的担忧。

### 发布新的 Move 模块[​](https://aptos.dev/transactions/interacting-with-the-aptos-blockchain#publishing-a-new-move-module) <a href="#publishing-a-new-move-module" id="publishing-a-new-move-module"></a>

发布新模块的 payload：

```
"type": "module_bundle_payload",
"modules": [
    {"bytecode": "0x..."},
],
```

这指示 VM 在发送者的帐户下发布模块字节码。 如需完整教程，请参阅您的第一个移动模块。

需要注意的是，Move 字节码必须指定与发送者账户相同的地址，否则交易将被拒绝。例如，假设账户地址为 `0xe110`，Move 模块需要更新如 `module 0xe110::Message`, `module 0xbar::Message` 将被拒绝。 或者，可以使用别名地址，例如模块 `module HelloBlockchain::Message` ，但 `HelloBlockchain` 别名需要在 Move.toml 文件中更新为 0xe110。 我们正在与 Move 团队合作，并计划将编译器合并到我们的 REST 接口中以缓解此问题。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.aptos.movemove.org/jiao-yi/yu-aptos-qu-kuai-lian-jiao-hu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
