Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions quickstart-template/mass-payout.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,13 @@ async function createAndFundSendingWallet() {

// Read from CSV file and send mass payout.
async function sendMassPayout(sendingWallet) {
// Define amount to send.
// Define a variable for the amount and assetId to transfer.
const transferAmount = 0.000002;
const assetId = Coinbase.assets.Eth;

// Array to store pending transfers for batch processing
const pendingTransfers = [];

try {
const parser = fs
.createReadStream("./wallet-array.csv")
Expand All @@ -76,14 +79,26 @@ async function sendMassPayout(sendingWallet) {
destination: address,
});

await transfer.wait();

console.log(`Transfer to ${address} successful`);
// Store transfer for later batch processing instead of waiting immediately
pendingTransfers.push({ address, transfer });
console.log(`Transfer to ${address} queued`);
} catch (error) {
console.error(`Error transferring to ${address}: `, error);
console.error(`Error creating transfer to ${address}: `, error);
}
}
}

// Wait for all transfers to complete in parallel for better performance
console.log(`\nWaiting for ${pendingTransfers.length} transfers to complete...`);

for (const { address, transfer } of pendingTransfers) {
try {
await transfer.wait();
console.log(`Transfer to ${address} completed successfully`);
} catch (error) {
console.error(`Transfer to ${address} failed: `, error);
}
}
} catch (error) {
console.error(`Error processing CSV file: `, error);
}
Expand Down