Orderless Transactions
Orderless transactions allow you to create transactions that do not specify a order of execution between them. This is particularly useful in scenarios where multiple machines need to sign a transaction, but the order in which they sign does not affect the outcome of the transaction or matter to the creator.
Building Orderless Transactions
Section titled “Building Orderless Transactions”Creating and executing a multi-agent transaction follows a similar flow to the simple transaction flow, and the multi-agent transaction flow.
For example, to create a single signer transaction that uses orderless transactions,
specify the nonce
in the build.simple
method like so:
const transaction = await aptos.transaction.build.simple({ sender: sender.accountAddress, data: { // All transactions on Aptos are implemented via smart contracts. function: "0x1::aptos_account::transfer", functionArguments: [destination.accountAddress, 100], }, options: { replayProtectionNonce: 12345, // This is the nonce that will be used to ensure the transaction is unique. }});
Similarly, if you are building a multi-agent transaction, you can specify the
replayProtectionNonce
in the build.multiAgent
method:
const transaction = await aptos.transaction.build.multiAgent({ sender: sender.accountAddress, secondarySignerAddresses: [bob.accountAddress], // List of secondary signers data: { // All transactions on Aptos are implemented via smart contracts. function: "0x1::aptos_account::transfer", functionArguments: [destination.accountAddress, 100], }, options: { replayProtectionNonce: 12345, // This is the nonce that will be used to ensure the transaction is unique. }});
And the same if you are building a sponsored transaction, you can specify the
replayProtectionNonce
in the build.multiAgent
method:
const transaction = await aptos.transaction.build.multiAgent({ sender: sender.accountAddress, withFeePayer: true, // This indicates that the transaction will be sponsored. data: { // All transactions on Aptos are implemented via smart contracts. function: "0x1::aptos_account::transfer", functionArguments: [destination.accountAddress, 100], }, options: { replayProtectionNonce: 12345, // This is the nonce that will be used to ensure the transaction is unique. }});
After that, simply follow the same steps as you would for a simple transaction:
- Simulate the transaction (optional).
- Sign the transaction.
- Submit the transaction to the network.
- Wait for the transaction to be executed.