Skip to content
Merged
Show file tree
Hide file tree
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
42 changes: 18 additions & 24 deletions src/pages/docs/guide/payments/send-a-payment.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -1009,6 +1001,8 @@ Send multiple payments in a single transaction using batch transactions:
</Tab>
</Tabs>

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:
Expand Down
7 changes: 4 additions & 3 deletions src/pages/docs/guide/payments/transfer-memos.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading