Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit a98dd12

Browse files
committed
[sdks] Add orderless docs for TypeScript
1 parent 349774a commit a98dd12

File tree

5 files changed

+136
-4
lines changed

5 files changed

+136
-4
lines changed

apps/nextra/pages/en/build/guides/_meta.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ export default {
3737
"sponsored-transactions": {
3838
title: "Sponsored Transactions",
3939
},
40+
"orderless-transactions": {
41+
title: "Orderless Transactions",
42+
},
4043
"transaction-management": {
4144
title: "Transaction Management",
4245
},
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Orderless Transactions
2+
3+
As outlined
4+
in [AIP-123](https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-123.md),
5+
orderless transactions allow for transactions to be executed out of order, which
6+
is particularly useful in scenarios where multiple machines need to sign for a
7+
single sending account, but the order in which they sign does not affect the
8+
outcome of the transaction or matter to the creator. Replay is protected in
9+
10+
## Process Overview
11+
12+
Orderless transactions are dependent on the transaction payload specified in
13+
[AIP-129](https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-129.md).
14+
The process for building and executing an orderless transaction is as follows:
15+
16+
1. Build a transaction with a `replayProtectionNonce` and a `TransactionPayload::TransactionPayloadPayload` that defines the operation to be executed.
17+
2. Sign and submit the transaction as any other transaction, but with the
18+
`replayProtectionNonce` set.
19+
20+
Note, that the behavior of the `replayProtectionNonce` is similar to a sequence
21+
number, but it does not guarantee ordered execution of transactions. Instead, it
22+
ensures that the transaction is unique and cannot be replayed (executed twice)
23+
with the same nonce.
24+
25+
## SDK Support
26+
27+
These are demonstrations of sponsored transactions:
28+
29+
- The [TypeScript SDK](../sdks/ts-sdk/building-transactions/orderless-transactions.mdx) has documentation
30+
- The [Go SDK](https://github.com/aptos-labs/aptos-go-sdk/tree/main/examples/orderless_transaction) has an example

apps/nextra/pages/en/build/sdks/ts-sdk/building-transactions.mdx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ Building and sending transactions on-chain involves the following 5 steps:
201201
Transactions have a couple of additional features which let them adapt to your needs which you can learn about here:
202202

203203
1. [Multi-Agent Signatures](building-transactions/multi-agent-transactions.mdx) - Allowing multiple accounts to be used for a single contract.
204-
2. [Sponsoring Transactions](building-transactions/sponsoring-transactions.mdx) - Have another account pay gas fees for this transaction.
205-
3. [Batch Submit Transactions](building-transactions/batching-transactions.mdx) - How to send multiple transactions quickly from a single account.
206-
4. [Binary Canonical Serialization (BCS)](building-transactions/bcs-format.mdx) - The format used to serialize data for Aptos transactions.
207-
5. [Composing multiple Move calls with ScriptComposer](building-transactions/script-composer.mdx) - (Experimental) Building more complex transaction payload that calls into multiple Move functions dynamically.
204+
2. [Orderless Signatures](building-transactions/orderless-transactions.mdx) - Allowing for transactions to be executed out of order for easier management.
205+
3. [Sponsoring Transactions](building-transactions/sponsoring-transactions.mdx) - Have another account pay gas fees for this transaction.
206+
4. [Batch Submit Transactions](building-transactions/batching-transactions.mdx) - How to send multiple transactions quickly from a single account.
207+
5. [Binary Canonical Serialization (BCS)](building-transactions/bcs-format.mdx) - The format used to serialize data for Aptos transactions.
208+
7. [Composing multiple Move calls with ScriptComposer](building-transactions/script-composer.mdx) - (Experimental) Building more complex transaction payload that calls into multiple Move functions dynamically.

apps/nextra/pages/en/build/sdks/ts-sdk/building-transactions/_meta.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ export default {
55
"multi-agent-transactions": {
66
title: "Multi-Agent Transactions",
77
},
8+
"orderless-transactions": {
9+
title: "Orderless Transactions",
10+
},
811
"sponsoring-transactions": {
912
title: "Sponsoring Transactions",
1013
},
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
title: "Orderless Transactions"
3+
---
4+
5+
import { Callout } from 'nextra/components'
6+
7+
# Orderless Transactions
8+
9+
Orderless transactions allow you to create transactions that do not specify a
10+
order of execution between them. This is particularly useful
11+
in scenarios where multiple machines need to sign a transaction, but the order
12+
in which they sign does not affect the outcome of the transaction or matter to
13+
the creator.
14+
15+
## Building Orderless Transactions
16+
17+
Creating and executing a multi-agent transaction follows a similar flow to the
18+
[simple transaction flow](../building-transactions.mdx), and the
19+
[multi-agent transaction flow](./multi-agent-transactions.mdx).
20+
21+
<Callout type="info">
22+
Instead of providing a `sequenceNumber` (or no sequence number at all), a
23+
`Replay Protection Nonce` is used to ensure that the transaction is unique and
24+
cannot be replayed (i.e., executed multiple times with the same nonce).
25+
</Callout>
26+
27+
For example, to create a single signer transaction that uses orderless transactions,
28+
specify the `nonce` in the `build.simple` method like so:
29+
30+
```ts filename="build-a-transaction.ts"
31+
const transaction = await aptos.transaction.build.simple({
32+
sender: sender.accountAddress,
33+
data: {
34+
// All transactions on Aptos are implemented via smart contracts.
35+
function: "0x1::aptos_account::transfer",
36+
functionArguments: [destination.accountAddress, 100],
37+
},
38+
options: {
39+
replayProtectionNonce: 12345, // This is the nonce that will be used to ensure the transaction is unique.
40+
}
41+
});
42+
```
43+
44+
Similarly, if you are building a multi-agent transaction, you can specify the
45+
`replayProtectionNonce` in the `build.multiAgent` method:
46+
47+
```ts filename="build-a-transaction.ts"
48+
const transaction = await aptos.transaction.build.multiAgent({
49+
sender: sender.accountAddress,
50+
secondarySignerAddresses: [bob.accountAddress], // List of secondary signers
51+
data: {
52+
// All transactions on Aptos are implemented via smart contracts.
53+
function: "0x1::aptos_account::transfer",
54+
functionArguments: [destination.accountAddress, 100],
55+
},
56+
options: {
57+
replayProtectionNonce: 12345, // This is the nonce that will be used to ensure the transaction is unique.
58+
}
59+
});
60+
```
61+
62+
And the same if you are building a sponsored transaction, you can specify the
63+
`replayProtectionNonce` in the `build.multiAgent` method:
64+
```ts filename="build-a-transaction.ts"
65+
const transaction = await aptos.transaction.build.multiAgent({
66+
sender: sender.accountAddress,
67+
withFeePayer: true, // This indicates that the transaction will be sponsored.
68+
data: {
69+
// All transactions on Aptos are implemented via smart contracts.
70+
function: "0x1::aptos_account::transfer",
71+
functionArguments: [destination.accountAddress, 100],
72+
},
73+
options: {
74+
replayProtectionNonce: 12345, // This is the nonce that will be used to ensure the transaction is unique.
75+
}
76+
});
77+
```
78+
79+
<Callout type="info">
80+
For orderless transactions, the `replayProtectionNonce` must be unique for
81+
each transaction. Additionally, the expiration time of the transaction is
82+
maximum 60 seconds from the time it is submitted. If the transaction is not
83+
executed within that time, it will be considered expired and will not be
84+
executed.
85+
</Callout>
86+
87+
After that, simply follow the same steps as you would for a simple transaction:
88+
1. [**Simulate** the transaction (optional)](./simulating-transactions).
89+
2. **Sign** the transaction.
90+
3. **Submit** the transaction to the network.
91+
4. **Wait** for the transaction to be executed.
92+
93+
### Examples
94+
95+
* [TS SDK Example](https://github.com/aptos-labs/aptos-ts-sdk/blob/main/examples/typescript/simple_orderless_transfer.ts)

0 commit comments

Comments
 (0)