跳转到内容

Sponsored Transactions (Fee Payer)

此内容尚不支持你的语言。

The Kotlin SDK provides support for sponsored transactions also known as fee payer transactions.

The standard flow for sending a sponsored transaction is as follows:

  1. Determine upon operation by creating a Transaction
  2. The sender signs the transaction
  3. The fee payer signs the transaction
  4. Submit the transaction

As seen in previous sections, you can build a transaction using buildSimpleTransaction with the lean transaction builder. For sponsored transactions, specify 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)
}

Once built, the sender signs the transaction using sign.

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

The fee payer signs using signAsFeePayer.

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

Submit the transaction with both authenticators.

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