Saltearse al contenido

Sponsored Transactions (Fee Payer)

Esta página aún no está disponible en tu idioma.

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 we’d already seen in the previous section, you can build a transaction by yourself using the buildTransaction.simple method or use the pre-built transaction builders like transferCoinTransaction. However, in the case of sponsored transactions, you need to specify the optional withFeePayer parameter as true in all cases.

val txn = aptos.buildTransaction.simple(
sender = alice.accountAddress,
data =
entryFunctionData {
function = "0x1::coin::transfer"
typeArguments = typeArguments { +TypeTagStruct("0x1::aptos_coin::AptosCoin") }
functionArguments = functionArguments {
+bob.accountAddress
+U64(SEND_AMOUNT_UNITS.toULong())
}
},
withFeePayer = true,
)

OR

val txn = aptos.transferCoinTransaction(
sender = alice,
receiver = bob.accountAddress,
amount = SEND_AMOUNT_UNITS,
withFeePayer = true,
)

Once you have built a transaction, you (the sender) can sign it using the sign method.

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

To sign the transaction as a fee payer, you can use the signAsFeePayer method.

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

Finally, you can submit the transaction to the network using the submit method.

val committedTxn = aptos.submitTransaction.simple(
transaction = txn,
senderAuthenticator = aliceAuthenticator,
feePayerAuthenticator = signerAuthenticator,
)