diff --git a/src/pages/docs/guide/payments/send-a-payment.mdx b/src/pages/docs/guide/payments/send-a-payment.mdx index 95dc757e..4787844d 100644 --- a/src/pages/docs/guide/payments/send-a-payment.mdx +++ b/src/pages/docs/guide/payments/send-a-payment.mdx @@ -708,30 +708,22 @@ Send multiple payments in a single transaction using batch transactions: import { Abis } from 'viem/tempo' import { client } from './viem.config' - const tokenABI = Abis.tip20 - const recipient1 = '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb' - const recipient2 = '0x70997970C51812dc3A010C7d01b50e0d17dc79C8' - - const calls = [ // [!code hl] - { // [!code hl] - to: '0x20c0000000000000000000000000000000000001', // [!code hl] - data: encodeFunctionData({ // [!code hl] - abi: tokenABI, // [!code hl] - functionName: 'transfer', // [!code hl] - args: [recipient1, parseUnits('100', 6)], // [!code hl] - }), // [!code hl] - }, // [!code hl] - { // [!code hl] - to: '0x20c0000000000000000000000000000000000001', // [!code hl] - data: encodeFunctionData({ // [!code hl] - abi: tokenABI, // [!code hl] - functionName: 'transfer', // [!code hl] - args: [recipient2, parseUnits('50', 6)], // [!code hl] - }), // [!code hl] - }, // [!code hl] - ] // [!code hl] - - const hash = await client.sendTransaction({ calls }) + const token = '0x20c0000000000000000000000000000000000001' as const + const payments = [ + { to: '0x742d35cc6634c0532925a3b844bc9e7595f0bebb', amount: parseUnits('100', 6) }, + { to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', amount: parseUnits('50', 6) }, + ] as const + + const calls = payments.map(({ to, amount }) => ({ // [!code hl] + to: token, // [!code hl] + data: encodeFunctionData({ // [!code hl] + abi: Abis.tip20, // [!code hl] + functionName: 'transfer', // [!code hl] + args: [to, amount], // [!code hl] + }), // [!code hl] + })) // [!code hl] + + await client.sendTransaction({ calls }) // [!code hl] ``` ```ts twoslash [viem.config.ts] @@ -1009,6 +1001,8 @@ Send multiple payments in a single transaction using batch transactions: +Pass every encoded call together so Tempo executes all transfers in one all-or-nothing transaction. + ### Index payment events When you send a payment, the token contract emits events: diff --git a/src/pages/docs/guide/payments/transfer-memos.mdx b/src/pages/docs/guide/payments/transfer-memos.mdx index a5c2f76d..708e74d7 100644 --- a/src/pages/docs/guide/payments/transfer-memos.mdx +++ b/src/pages/docs/guide/payments/transfer-memos.mdx @@ -135,22 +135,23 @@ await Actions.token.transferSync(walletClient, { ### Payroll batch payments -Batch multiple payments in a single Tempo transaction with employee IDs in each memo for clear accounting records. +Start with the [Viem batch payment setup](/docs/guide/payments/send-a-payment#batch-payment-transactions), then encode `transferWithMemo` for each employee ID. ```ts import { Abis } from 'viem/tempo' import { encodeFunctionData, parseUnits, stringToHex, pad } from 'viem' +import { client } from './viem.config' const calls = employees.map(emp => ({ to: tokenAddress, data: encodeFunctionData({ - abi: Abis.TIP20, + abi: Abis.tip20, functionName: 'transferWithMemo', args: [emp.wallet, parseUnits(emp.salary, 6), pad(stringToHex(emp.id), { size: 32 })] }) })) -await walletClient.sendCalls({ calls }) +await client.sendTransaction({ calls }) ``` ### Refund address in memo