Skip to main content
Conditions allow transactions to wait until specific requirements are met before executing.

createCondition

Create a condition that must be satisfied for execution.
import { createCondition, ConditionType } from "@biconomy/abstractjs";

const condition = createCondition(options);

Parameters

ParameterTypeRequiredDescription
targetContractAddressYesContract to call
functionAbiAbiYesABI containing the function
functionNamestringYesView/pure function name
argsany[]YesFunction arguments
valuebigintYesThreshold or expected value
typeConditionTypeYesComparison type
descriptionstringNoHuman-readable description

Returns

Condition - Can be passed to buildComposable

Example

import { createCondition, ConditionType } from "@biconomy/abstractjs";
import { erc20Abi, parseUnits } from "viem";

const minBalance = createCondition({
  targetContract: USDC,
  functionAbi: erc20Abi,
  functionName: "balanceOf",
  args: [userAddress],
  value: parseUnits("100", 6),
  type: ConditionType.GTE,
  description: "User must have at least 100 USDC"
});

ConditionType

enum ConditionType {
  GTE = "gte",  // Greater than or equal (≥)
  LTE = "lte",  // Less than or equal (≤)
  EQ = "eq"     // Equal (=)
}

Usage Examples

// Balance must be at least 1000 tokens
createCondition({
  ...
  value: parseUnits("1000", 18),
  type: ConditionType.GTE
});

// Price must not exceed maximum
createCondition({
  ...
  value: maxPrice,
  type: ConditionType.LTE
});

// Contract must not be paused (paused = false = 0)
createCondition({
  ...
  value: 0n,
  type: ConditionType.EQ
});

Adding Conditions to Instructions

const instruction = await account.buildComposable({
  type: "transfer",
  data: {
    chainId: 8453,
    tokenAddress: USDC,
    recipient: "0x...",
    amount: parseUnits("50", 6),
    conditions: [minBalanceCondition]  // Add conditions here
  }
});

Multiple Conditions (AND Logic)

All conditions must pass for execution:
const instruction = await account.buildComposable({
  type: "default",
  data: {
    chainId: 8453,
    to: lendingProtocol,
    abi: lendingAbi,
    functionName: "borrow",
    args: [amount],
    conditions: [
      // Condition 1: Sufficient collateral
      createCondition({
        targetContract: collateralToken,
        functionAbi: erc20Abi,
        functionName: "balanceOf",
        args: [userAddress],
        value: minCollateral,
        type: ConditionType.GTE
      }),
      
      // Condition 2: Healthy position
      createCondition({
        targetContract: lendingProtocol,
        functionAbi: lendingAbi,
        functionName: "getHealthFactor",
        args: [userAddress],
        value: parseUnits("1.5", 18),
        type: ConditionType.GTE
      }),
      
      // Condition 3: Protocol not paused
      createCondition({
        targetContract: lendingProtocol,
        functionAbi: lendingAbi,
        functionName: "paused",
        args: [],
        value: 0n,
        type: ConditionType.EQ
      })
    ]
  }
});

Waiting for Conditions

Set a timeout for how long to wait:
const quote = await meeClient.getFusionQuote({
  trigger,
  instructions: [instruction],
  feeToken,
  upperBoundTimestamp: Math.floor(Date.now() / 1000) + 300  // Wait up to 5 min
});

Execution Flow

  1. Submit - Transaction submitted with conditions
  2. PENDING - MEE periodically checks conditions
  3. Satisfied - All conditions pass → execute
  4. Timeout - Conditions not met in time → fail

Common Patterns

Contract Not Paused

const pausableAbi = [{
  inputs: [],
  name: "paused",
  outputs: [{ name: "", type: "bool" }],
  stateMutability: "view",
  type: "function"
}] as const;

createCondition({
  targetContract: protocol,
  functionAbi: pausableAbi,
  functionName: "paused",
  args: [],
  value: 0n,  // false
  type: ConditionType.EQ
});

Minimum Balance

createCondition({
  targetContract: USDC,
  functionAbi: erc20Abi,
  functionName: "balanceOf",
  args: [userAddress],
  value: parseUnits("50", 6),
  type: ConditionType.GTE
});

Price Threshold

createCondition({
  targetContract: priceOracle,
  functionAbi: oracleAbi,
  functionName: "getPrice",
  args: [tokenAddress],
  value: targetPrice,
  type: ConditionType.GTE  // Wait for price to reach target
});

Best Practices

PracticeReason
Match decimal precisionUSDC = 6, WETH = 18
Limit to 1-3 conditionsEach adds ~5-10k gas
Use as const for ABIsEnables type inference
Set reasonable timeoutsPrevent indefinite waiting
Add descriptionsImproves debugging