Add example for batch transactions using Aptos SDK#585
Open
Akk525 wants to merge 1 commit intoaptos-labs:mainfrom
Open
Add example for batch transactions using Aptos SDK#585Akk525 wants to merge 1 commit intoaptos-labs:mainfrom
Akk525 wants to merge 1 commit intoaptos-labs:mainfrom
Conversation
gregnazario
reviewed
Nov 19, 2024
Collaborator
gregnazario
left a comment
There was a problem hiding this comment.
We generally have avoided the JavaScript examples, just because we already are building them in TypeScript, which tends to have better practices / showing how to manage types (where JavaScript you can omit them).
I'm curious have you seen this example in TypeScript?
It uses a transaction worker thread to manage the batch send, which might not be exactly what you want.
I'd love feedback as well if JavaScript examples are important rather than just TypeScript.
cc @0xmaayan
Comment on lines
+66
to
+71
| // Loop through each transaction payload, send the transaction, and track its hash | ||
| for (const txPayload of transactions) { | ||
| const txHash = await sendTransaction(txPayload); // Send the transaction and get its hash | ||
| transactionHashes.push(txHash); // Store the transaction hash in the array | ||
| console.log(`Transaction submitted with hash: ${txHash}`); // Log the transaction hash | ||
| } |
Collaborator
There was a problem hiding this comment.
If you're looking to send multiple transactions at once, should probably do these in parallel and handle the sequence number appropriately.
Suggested change
| // Loop through each transaction payload, send the transaction, and track its hash | |
| for (const txPayload of transactions) { | |
| const txHash = await sendTransaction(txPayload); // Send the transaction and get its hash | |
| transactionHashes.push(txHash); // Store the transaction hash in the array | |
| console.log(`Transaction submitted with hash: ${txHash}`); // Log the transaction hash | |
| } | |
| // Loop through each transaction payload, send the transaction, and track its hash | |
| const promises = transactions.map((payload) => sendTransaction(payload)); // Handle errors here | |
| const transactionHashes = Promise.all(promises); | |
| console.log(`Transactions submitted with hashes: ${JSON.stringify(transactionHashes)}`); // Log the transaction hashes | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request adds a new example,
batchTransactions.js, to theexamples/javascriptdirectory. The example demonstrates how to perform batch transactions using the Aptos SDK, showcasing the process of sending multiple transactions sequentially in a script. This example is designed to help developers optimize workflows that involve multiple on-chain operations.Test Plan