Aptos Payload Transaction

A general Aptos transaction is used mainly for invoking non-transfer transactions.

Fordefi can handle any Aptos entry function transaction. While such transactions can be used to create transfers, it is recommended to use their request formats.

To invoke a general transaction using the Fordefi platform, you need to provide the following:

  • The gas configuration

  • The serialized transaction payload in base64 format

    📘

    Note

    API users must strongly authenticate transaction requests that are created programmatically by signing them. Learn more.

The following example creates a transaction request that swaps Aptos (APT) to PancakeSwap (CAKE) on SushiSwap. The request should be inside the body, as demonstrated here.

{
  "signer_type": "api_signer",
  "type": "aptos_transaction",
  "details": {
    "type": "aptos_serialized_entry_point_payload",
    "chain": "aptos_mainnet",
    "gas_config": {
      "price": {
        "type": "priority",
        "priority": "medium"
      },
    },
    "serialized_transaction_payload": "AsfvtAdtvhQ8vNmM+qqSns/I8pkgPf/2O5XMtr/hmFD6BnJvdXRlchpzd2FwX2V4YWN0X2lucHV0X2RvdWJsZWhvcAMHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEKYXB0b3NfY29pbglBcHRvc0NvaW4AB14VbxIH0Ov6Ganu/wDWKigiePuHGfT6s6WGoKLA//vqBGNvaW4BVAAHFZ32t2iUNwFhCKAZ/Vvvc2usaSttSh8QyUH2+7mnTKYDb2Z0B0Nha2VPRlQAAgighgEAAAAAAAjjYAUAAAAAAA=="
  },
  "note": "Swapping APT to CAKE",
  "vault_id": "8988893a-cf29-4a02-acc7-5bb723c74f47"
}

Aptos SDK for building serialized transaction payload

Building the serialized transaction payload can be done using any of several Aptos SDKs. One example is the Aptos Python package. The following example demonstrates how to obtain the serialized payload of the swap transaction from APT to CAKE on SushiSwap.

First, install the Aptos Python package, and run the following snippet to obtain the serialized payload:

import base64

import aptos_sdk
import aptos_sdk.account
import aptos_sdk.account_address
import aptos_sdk.async_client
import aptos_sdk.bcs
import aptos_sdk.transactions
import aptos_sdk.type_tag

entry_function = aptos_sdk.transactions.EntryFunction.natural(
    module="0xc7efb4076dbe143cbcd98cfaaa929ecfc8f299203dfff63b95ccb6bfe19850fa::router",
    function="swap_exact_input_doublehop",
    ty_args=[
        aptos_sdk.type_tag.TypeTag(aptos_sdk.type_tag.StructTag.from_str("0x1::aptos_coin::AptosCoin")),
        aptos_sdk.type_tag.TypeTag(aptos_sdk.type_tag.StructTag.from_str("0x5e156f1207d0ebfa19a9eeff00d62a282278fb8719f4fab3a586a0a2c0fffbea::coin::T")),
        aptos_sdk.type_tag.TypeTag(aptos_sdk.type_tag.StructTag.from_str("0x159df6b7689437016108a019fd5bef736bac692b6d4a1f10c941f6fbb9a74ca6::oft::CakeOFT")),
    ],
    args=[
        aptos_sdk.transactions.TransactionArgument(
            value=100000,
            encoder=aptos_sdk.bcs.Serializer.u64,
        ),
        aptos_sdk.transactions.TransactionArgument(
            value=352483,
            encoder=aptos_sdk.bcs.Serializer.u64,
        ),
    ],
)
payload = aptos_sdk.transactions.TransactionPayload(entry_function)
serializer = aptos_sdk.bcs.Serializer()
payload.serialize(serializer)
data = serializer.output() 
serialized_data = base64.b64encode(data)

print(serialized_data)