> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://viem-f85wz2hbq-wevm.vercel.app/api/mcp` to find what you need.

# Funding Transactions

## Overview

`requireFunds` specifies token balances to satisfy before transaction calls execute. Existing balances count toward each requirement. Funding sources run in order to supply the shortfall, and funding reverts with a failed payment.

This preview requires a TIP-1120-enabled node. It does not enable funding on public networks. Source addresses must match the target deployment.

## Recipes

These recipes assume you have [set up a Tempo client](/tempo).

### Fund a Transaction

Use [`sendTransaction`](/docs/actions/wallet/sendTransaction) with complete requirements. `DexFundingSource.encode` encodes native DEX source data. This example sources up to 30 pathUSD, then uses USDC.e for the remaining OUSD shortfall.

:::code-group
```ts [example.ts]
import { Addresses, Actions, DexFundingSource } from 'viem/tempo'
import { client } from './viem.config'

const ousd = '0x...' // Output token address.
const usdcE = '0x...' // Second input token address.

await client.sendTransaction({
  calls: [
    Actions.token.transfer.call({ token: ousd, to: '0x...', amount: 50_000_000n }),
  ],
  requireFunds: [{
    token: ousd,
    amount: 50_000_000n,
    slippageBps: 100,
    sources: [
      {
        to: Addresses.nativeDexFundingSource,
        data: DexFundingSource.encode({
          tokenIn: Addresses.pathUsd,
          maxAmountIn: 30_000_000n,
        }),
      },
      {
        to: Addresses.nativeDexFundingSource,
        data: DexFundingSource.encode({ tokenIn: usdcE }),
      },
    ],
  }],
})
```

```ts [viem.config.ts]
// [!include ~/snippets/tempo/viem.config.ts:setup]
```
:::

### Fund a Token Transfer

Pass `requireFunds` to [`token.transferSync`](/tempo/actions/token.transfer) when sending a single token transfer. The action funds the required OUSD balance before transferring it.

:::code-group
```ts [example.ts]
import { Addresses, DexFundingSource } from 'viem/tempo'
import { client } from './viem.config'

const ousd = '0x...' // Output token address.

await client.token.transferSync({
  token: ousd,
  to: '0x...',
  amount: 50_000_000n,
  requireFunds: [{
    token: ousd,
    amount: 50_000_000n,
    slippageBps: 100,
    sources: [{
      to: Addresses.nativeDexFundingSource,
      data: DexFundingSource.encode({ tokenIn: Addresses.pathUsd }),
    }],
  }],
})
```

```ts [viem.config.ts]
// [!include ~/snippets/tempo/viem.config.ts:setup]
```
:::

## Best Practices

* Requirements specify target balances, not additional amounts. Repeated token entries are processed in order.
* `slippageBps` applies across all sources in a requirement. Zero allows no aggregate loss; omission uses the protocol default.
* Source caps use input token base units. Omission in `DexFundingSource.encode` allows the maximum input amount, subject to protocol limits.
* Funding cannot pay transaction fees. Hold a supported fee token or use [fee sponsorship](/tempo/guides/sponsor-fees).
* Owner-authorized requirements omit `policyRules`.

The pinned draft node can underestimate gas for some funding paths. The E2E fixtures supply an explicit gas limit; verify estimates against your target node before deployment.

## See More

* [Estimate Gas](/docs/actions/public/estimateGas)
* [Prepare Transaction Request](/docs/actions/wallet/prepareTransactionRequest)
* [Token Transfers](/tempo/actions/token.transfer)
