From c423156a680809f63b28063e3cd1ae22ff9cc42e Mon Sep 17 00:00:00 2001 From: Kubudak90 Date: Tue, 7 Apr 2026 14:39:19 +0300 Subject: [PATCH] fix: enable proper batching in mass-payout.js example The original code waited for each transfer to complete inside the loop, which defeated the purpose of batching. This fix: 1. Collects all transfers first without waiting for confirmation 2. Waits for all transfers to complete in a separate loop 3. Improves performance by allowing parallel processing 4. Adds better error handling for each phase Fixes #416 --- quickstart-template/mass-payout.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/quickstart-template/mass-payout.js b/quickstart-template/mass-payout.js index 7131b0ab..0cef1c7c 100644 --- a/quickstart-template/mass-payout.js +++ b/quickstart-template/mass-payout.js @@ -56,15 +56,17 @@ async function createAndFundSendingWallet() { // Read from CSV file and send mass payout. async function sendMassPayout(sendingWallet) { - // Define amount to send. + // Define amount and assetId for transfer. 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 without waiting for confirmation (enables batching) for await (const row of parser) { const address = row[0]; if (address) { @@ -76,14 +78,24 @@ 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 + console.log(`\nWaiting for ${transfers.length} transfers to complete...`); + for (const { address, transfer } of transfers) { + try { + await transfer.wait(); + console.log(`Transfer to ${address} successful`); + } catch (error) { + console.error(`Transfer to ${address} failed: `, error); + } + } } catch (error) { console.error(`Error processing CSV file: `, error); }