# 最新的 Sui Network 支付交易类型（附教程）

By [MetaverseFI](https://paragraph.com/@metaverseficapital) · 2022-11-06

---

最新的 Sui 版本引入了三种新的支付交易类型（Pay、PaySui和PayAllSui ）并弃用了三种原有方法（TransferSui、SplitCoin和MergeCoin）。三种较旧的方法暂时仍然有效，我们将在删除它们之前提前通知社区。

这些支付方式提供了更大的简便性，并且可以以更少的Token管理开销支持各种场景。我们希望开发人员能够找到更多的灵活性来支持更加广泛的用例，以及支付产品他们所期望的更加强大的 API。

目前这三种新的交易类型（Pay, PaySui, and PayAllSui）已作为 Sui 0.14.0 的更新一部分发布。

**崭新的支付交易类型**

Pay交易采用多币种并按照指定的金额列表发送到多个地址。Pay交易将采用任何类型的Token，包括 SUI。GAS费用的支付将会使用一个单独的SUI为对象，如果需要，协议将选择一个用于交易。

如果接收地址和发送地址相同，Pay 交易实际上是 splitCoin 和 mergeCoin 的通用版本

**PaySui交易采用多个 SUI 并按照指定的金额列表发送到多个地址。Pay Sui 只需要 SUI Token，不需要GAS币对象。**

1、第一个 SUI 币对象输入将用于支付 gas，因此该 SUI 币的余额必须大于或等于 gas 费用的预算。

2、 当需要转移时，SUI 的余额输入必须包括 gas 费的预算和要转移的金额。

**PayAllSui 交易类型发件人可以通过这种交易类型将他们所有的 SUI 币转移到另一个地址。交易完成后，全部的SUI 币将转移到新的地址上。**

1、当转移 SUI 币时，链上将会先扣GAS费，因此转移 SUI 币的余额必须大于或等于 gas 费的预算。

2、发件人可以通过这种交易类型将他们所有的 SUI 硬币转移到另一个地址，在一次交易中 SUI 严格为零。

**迁移指南**

以下是基于 Typescript SDK 的迁移代码示例。这些更改与用于 Rust SDK 和 RPC 端点的更改非常相似。

**指定数量的TransferSui将迁移到PaySui**

    // pre-migration codes in TS
    const txn = {
        suiObjectId: id,
        gasBudget: GAS_BUDGET,
        recipient: recipient_addr,
        amount: amount,
    };
    await signer.transferSuiWithRequestType(txn);
    
    
    // post-migration codes in TS
    const txn = {
        inputCoins: [id],
        // length of recipients need to be the same as amounts
        recipients: [recipient_addr],
        amounts: [amount],
        gasBudget: GAS_BUDGET,
    };
    await signer.paySuiWithRequestType(txn);
    

**没有指定金额的 TransferSui 将迁移到 PayAllSui**

    // pre-migration codes in TS
    const txn = {
        suiObjectId: id,
        gasBudget: GAS_BUDGET,
        recipient: recipient_addr,
        amount: null,
    };
    await signer.transferSuiWithRequestType(txn);
    
    
    // post-migration codes in TS
    const txn = {
        inputCoins: [id],
        recipient: recipient_addr,
        gasBudget: GAS_BUDGET,
    };
    await signer.payAllSuiWithRequestType(txn);
    

SplitCoin和MergeCoin将迁移到Pay

    // pre-migration split coin
    const txn = {
      coinObjectId: id;
      splitAmounts: [amount0, amount1],
      gasPayment: gas_obj_id,
      gasBudget: GAS_BUDGET,
    };
    await signer.SplitCoinWithRequestType(txn);
    // post-migration pay txn for splitting
    const txn = {
      inputCoins: [id],
    // length of recipients need to be the same as amounts
      recipients: [sender_addr, sender_addr],
      amounts: [amount0, amount1],
      gasPayment: gas_obj_id,
      gasBudget: GAS_BUDGET,
    };
    await signer.PayWithRequestType(txn);
    
    
    // pre-migration merge coin
    const txn = {
      primaryCoin: primary_coin_id,
      coinToMerge: coin_to_merge,
      gasPayment?: gas_obj_id,
      gasBudget: GAS_BUDGET,
    };
    await signer.MergeCoinWithRequestType(txn);
    // post-migration pay txn for merging
    const txn = {
      inputCoins: [primary_coin_id, coin_to_merge],
      recipients: [sender_addr],
      amounts: [primary_coin_amount + coin_to_merge_amount],
      gasPayment: gas_obj_id,
      gasBudget: GAS_BUDGET,
    };
    await signer.PayWithRequestType(txn);
    

**正在进行时**

我们的团队将继续努力，进一步提高与支付相关的开发者体验和速度。我们正在开展的其他举措包括：

1、实现类似的util函数，如Move模块中的Pay。

2、引入GAS 估算模型以便更好地估算 GAS 预算和总 GAS 成本。

3、进一步改进各种应用案例的代币选择 API。

[Subscribe](null)

---

*Originally published on [MetaverseFI](https://paragraph.com/@metaverseficapital/sui-network)*
