跳转到内容

赞助交易(付费者)

Kotlin SDK 支持赞助交易,也称为付费者交易。

发送赞助交易的标准流程如下:

  1. 通过创建交易确定要执行的操作
  2. 发送者签名交易
  3. 付费者签名交易
  4. 提交交易

如前文所示,您可以结合精简交易构建器使用 buildSimpleTransaction 来构建交易。对于赞助交易,请指定 withFeePayer = true

val txn =
aptos.buildSimpleTransaction(
sender = alice.accountAddress,
withFeePayer = true,
) {
function = "0x1::coin::transfer"
typeArgs("0x1::aptos_coin::AptosCoin")
args(bob.accountAddress, 1_000_000UL)
}

交易构建完成后,发送者使用 sign 签名。

val aliceAuthenticator =
aptos.sign(signer = alice, transaction = txn)

付费者使用 signAsFeePayer 签名。

val feePayerAuthenticator =
aptos.signAsFeePayer(feePayer = sponsor, transaction = txn)

携带两个认证器提交交易。

val pendingTxn =
aptos
.submitTransaction.simple(
transaction = txn,
senderAuthenticator = aliceAuthenticator,
feePayerAuthenticator = feePayerAuthenticator,
)
.expect("Failed to submit transaction")