> ## Documentation Index
> Fetch the complete documentation index at: https://docs.biconomy.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Conditional Execution

> Attach runtime conditions to transactions

Transactions wait until conditions are met before executing—enabling limit orders, price triggers, and safe operations.

## Quick Example

```typescript theme={null}
import { createCondition, ConditionType } from '@biconomy/abstractjs';
import { erc20Abi, parseUnits } from 'viem';

// Only execute if balance >= 100 USDC
const minBalance = createCondition({
  targetContract: USDC,
  functionAbi: erc20Abi,
  functionName: 'balanceOf',
  args: [userAddress],
  value: parseUnits('100', 6),
  type: ConditionType.GTE
});

// Add condition to any instruction
const instruction = await account.buildComposable({
  type: 'transfer',
  data: {
    tokenAddress: USDC,
    recipient: recipientAddress,
    amount: transferAmount,
    chainId: base.id,
    conditions: [minBalance]  // ← Waits until satisfied
  }
});
```

## How It Works

```
Submit Transaction → Check Conditions → Pass? Execute : Wait (PENDING)
                                              ↓
                                    MEE rechecks periodically
                                              ↓
                                    Conditions pass → Execute
```

## Condition Types

| Type  | Meaning | Use Case                       |
| ----- | ------- | ------------------------------ |
| `GTE` | ≥ value | Minimum balance                |
| `LTE` | ≤ value | Maximum price                  |
| `EQ`  | = value | Exact state (e.g., not paused) |

## Common Patterns

### Minimum Balance

```typescript theme={null}
createCondition({
  targetContract: USDC,
  functionAbi: erc20Abi,
  functionName: 'balanceOf',
  args: [userAddress],
  value: parseUnits('50', 6),
  type: ConditionType.GTE
})
```

### Contract Not Paused

```typescript theme={null}
createCondition({
  targetContract: protocolAddress,
  functionAbi: pausableAbi,
  functionName: 'paused',
  args: [],
  value: 0n,  // false
  type: ConditionType.EQ
})
```

### Multiple Conditions (AND)

All conditions must pass:

```typescript theme={null}
const instruction = await account.buildComposable({
  type: 'default',
  data: {
    to: lendingProtocol,
    abi: lendingAbi,
    functionName: 'borrow',
    args: [amount],
    chainId: base.id,
    conditions: [
      // Must have collateral
      createCondition({
        targetContract: collateralToken,
        functionAbi: erc20Abi,
        functionName: 'balanceOf',
        args: [userAddress],
        value: minCollateral,
        type: ConditionType.GTE
      }),
      // Must be healthy
      createCondition({
        targetContract: lendingProtocol,
        functionAbi: lendingAbi,
        functionName: 'getHealthFactor',
        args: [userAddress],
        value: parseUnits('1.5', 18),
        type: ConditionType.GTE
      })
    ]
  }
});
```

## Waiting for Conditions

Set a timeout for how long to wait:

```typescript theme={null}
const quote = await meeClient.getFusionQuote({
  trigger: { chainId: base.id, tokenAddress: USDC, amount },
  instructions: [instruction],
  feeToken: { chainId: base.id, address: USDC },
  upperBoundTimestamp: Math.floor(Date.now() / 1000) + 300  // Wait up to 5 min
});

const { hash } = await meeClient.executeFusionQuote({ fusionQuote: quote });
// Transaction stays PENDING until condition met or timeout
```

## Use Cases

* **Limit orders**: Wait for price target
* **Balance triggers**: Execute when funds arrive
* **Safety checks**: Verify contract state before executing
* **Slippage protection**: Only swap at acceptable prices

## Best Practices

<CardGroup cols={2}>
  <Card title="Match Decimals" icon="check">
    USDC = 6, WETH = 18
  </Card>

  <Card title="Limit Conditions" icon="gauge">
    1-3 conditions optimal
  </Card>

  <Card title="Set Timeouts" icon="clock">
    Always set `upperBoundTimestamp`
  </Card>

  <Card title="Use `as const`" icon="code">
    For type-safe ABIs
  </Card>
</CardGroup>
