Skip to content

Go SDK - Orderless Transactions

Orderless transactions allow you to create transactions that do not specify an order of execution between them. This is useful when multiple machines need to sign or submit for the same sending account, but the order does not affect the outcome.

See Orderless Transactions for the protocol overview (AIP-123 and AIP-129).

Wrap the entry function in a TransactionInnerPayload and set ReplayProtectionNonce on TransactionExtraConfigV1. Cap expiration at 60 seconds with aptos.ExpirationSeconds(60).

replayNonce := uint64(100)
accountBytes, err := bcs.Serialize(&bob.Address)
if err != nil {
panic("Failed to serialize bob's address:" + err.Error())
}
amountBytes, err := bcs.SerializeU64(TransferAmount)
if err != nil {
panic("Failed to serialize transfer amount:" + err.Error())
}
rawTxn, err := client.BuildTransaction(
alice.AccountAddress(),
aptos.TransactionPayload{
Payload: &aptos.TransactionInnerPayload{
Payload: &aptos.TransactionInnerPayloadV1{
Executable: aptos.TransactionExecutable{
Inner: &aptos.EntryFunction{
Module: aptos.ModuleId{
Address: aptos.AccountOne,
Name: "aptos_account",
},
Function: "transfer",
ArgTypes: []aptos.TypeTag{},
Args: [][]byte{accountBytes, amountBytes},
},
},
ExtraConfig: aptos.TransactionExtraConfig{
Inner: &aptos.TransactionExtraConfigV1{
MultisigAddress: nil,
ReplayProtectionNonce: &replayNonce,
},
},
},
},
},
aptos.ExpirationSeconds(60),
)

After that, follow the same steps as a simple transaction:

  1. Simulate the transaction (optional).
  2. Sign the transaction.
  3. Submit the transaction to the network.
  4. Wait for the transaction to be executed.

BuildSignAndSubmitTransaction accepts the same inner payload if you want to skip the manual sign and submit steps.

The SDK repository includes a runnable example that follows this API:

Run it with:

Terminal window
go run examples/orderless_transaction/main.go