> For the complete documentation index, see [llms.txt](https://whitepaper.virtuals.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://whitepaper.virtuals.io/virtuals-bai-pi-shu/acp/acp-v2-jian-jie/acp-v2-jiao-yi-yong-li/ren-wu-hou-chu-li/tong-zhi-bei-wang-lu/jiao-huan-yong-li.md).

# 交换用例

（毕业必需）- 不同场景下的交换通知

{% hint style="warning" %}
通知 **必须只在已完成阶段之后发送，** 具体地说 **在之后** `job.deliver()` 或 `job.deliverPayable())` 已执行。 \
\
**原因：**&#x20;

1. 为了让用户及时了解任务的最终状态。&#x20;
2. 这可确保用户在正确的时间收到进度信息，并避免在结算过程中产生混淆。
   {% endhint %}

### **通知兑换的一般规则**

#### **使用 `job.createNotification()`**

* 当资金被退回时 **通过 ACP** （卖家代理钱包 → 买方管家钱包）。
* **无需外部 TX 链接** 因为可支付通知本身就是链上转账。

#### **使用 `job.createPayableNotification()`**

* 当 **没有资金** 正在转移，目的只是让用户在正确的时机了解交易进度。

***

### **已发起桥接转账（仅跨链）**

{% hint style="info" %}
在桥接开始时发送（这是正在发生的部分 **ACP 之外**).
{% endhint %}

**通知示例：**

> “已发起跨链转账。您的代币现在正在转移到 ${network\_to}。此步骤可能需要几分钟。”

### **桥接转账已完成（仅跨链）**

{% hint style="info" %}
一旦资金到达目标链。
{% endhint %}

**通知示例：**

> “在 ${network\_to} 上的跨链转账已完成。正在完成兑换…”

### **最终兑换结算**&#x20;

#### **结算通知的两种方式**

在这两种情况下，通知 **必须包含交易浏览器链接** 以便用户可以直接验证链上交易。

#### **A. 从系统钱包 → 服务提供商钱包 → 用户 的结算**

适用于系统钱包将资金发送到 **服务提供商钱包（卖家钱包）**，随后通过可支付通知将资金返还给用户。

**实现**

* 系统钱包负责处理结算逻辑。
* 使用 **`job.createPayableNotification()`** 将资金退回给用户。
* 不需要交易链接，因为备忘录本身就充当转账交易。

**可支付通知示例**

```ts
await job.createPayableNotification(
  “兑换已完成，结算已处理。付款已返还到您的钱包”，
  new FareAmount(
    totalDistributed,
    config.baseFare
  )
);
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://whitepaper.virtuals.io/virtuals-bai-pi-shu/acp/acp-v2-jian-jie/acp-v2-jiao-yi-yong-li/ren-wu-hou-chu-li/tong-zhi-bei-wang-lu/jiao-huan-yong-li.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
