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
19 changes: 15 additions & 4 deletions quickstart-template/mass-payout.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ async function sendMassPayout(sendingWallet) {
// Define amount to send.
const transferAmount = 0.000002;
const assetId = Coinbase.assets.Eth;
const transfers = [];

try {
const parser = fs
.createReadStream("./wallet-array.csv")
.pipe(parse({ delimiter: ",", from_line: 1 }));

// STEP 1: Queue all transfers (sequentially to enable batching)
for await (const row of parser) {
const address = row[0];
if (address) {
Expand All @@ -76,14 +78,23 @@ async function sendMassPayout(sendingWallet) {
destination: address,
});

await transfer.wait();

console.log(`Transfer to ${address} successful`);
transfers.push({ address, transfer });
console.log(`Queued transfer to ${address}`);
} catch (error) {
console.error(`Error transferring to ${address}: `, error);
console.error(`Error creating transfer to ${address}: `, error);
}
}
}

// STEP 2: Wait for all transfers to complete
for (const { address, transfer } of transfers) {
try {
await transfer.wait();
console.log(`Transfer to ${address} successful`);
} catch (error) {
console.error(`Error waiting for transfer to ${address}: `, error);
}
}
} catch (error) {
console.error(`Error processing CSV file: `, error);
}
Expand Down