# Portals Foresight — DeFi Batch Transaction Simulation API

> Portals Foresight — DeFi Batch Transaction Simulation API is a paid API for AI agents from foresight.portals.fi, paid per call via x402, $0.005/call, status unknown (last checked 2026-10-13).

Simulate multi-step DeFi transaction sequences (e.g. approve+swap, deposit+borrow) with shared state to validate entire strategies before executing on-chain.

## Facts

- Endpoint: POST https://foresight.portals.fi/v1/simulate/batch?utm_source=zero.xyz
- Price: $0.005/call
- Payment: x402
- Status: unknown
- Last checked: 2026-10-13
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/portals-foresight-defi-batch-transaction-simulation-api-c391e6d7
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_m7U6fr0GL7eAoQE8R4Ln6

Status and success rate cover calls made through Zero and Zero's own probes. Third-party monitors may report differently.

## How to call it through Zero

Zero handles the 402 payment challenge and records the run. With the Zero CLI installed (`npm i -g @zeroxyz/cli`):

```sh
zero fetch --capability portals-foresight-defi-batch-transaction-simulation-api-c391e6d7 -d '<json body>'
```

Example prompt: Before I execute this on-chain, simulate the two-step DeFi flow where I first approve and then swap 100 USDC (0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48, amount 100000000) to WETH from my wallet 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045 — use Portals Foresight to validate both steps together and show me the expected asset changes and total gas cost.

## When to prefer this

Use this endpoint when you need to validate a sequence of dependent DeFi operations (e.g. approve→swap, deposit→borrow) as a single atomic simulation with shared state, rather than simulating each transaction independently. It is ideal when you need to see aggregate asset changes and gas costs across the full strategy before committing funds on-chain.

## Known failure modes

- One or more steps fail simulation — success=false returned per step or at aggregate level
- Invalid or malformed contract address or calldata returns a 400 error
- Unsupported chain or token address not recognized
- Input amount exceeds simulated balance — step fails with revert
- customEvents array exceeds 10 entries — only first 10 are decoded
- Payment authorization failure via x402 — call not executed

## How this service works

Simulate multi-step DeFi flows (approve+swap, deposit+borrow) with shared state. Validate entire strategies before committing on-chain.

## Output

Returns per-step results (success flag, gas used, step index) plus an aggregate summary including total gas used, gas cost in wei, input tokens, output tokens, all asset changes with direction (sent/received), and token metadata (name, symbol, decimals) for each token involved.

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "required": [
  "input"
 ],
 "properties": {
  "input": {
   "type": "object",
   "required": [
    "type",
    "bodyType",
    "body",
    "method"
   ],
   "properties": {
    "body": {
     "required": [
      "sender",
      "steps"
     ],
     "properties": {
      "steps": {
       "type": "array",
       "items": {
        "type": "object",
        "required": [
         "tx"
        ],
        "properties": {
         "tx": {
          "type": "object",
          "required": [
           "from",
           "to",
           "data",
           "value"
          ],
          "properties": {
           "to": {
            "type": "string"
           },
           "data": {
            "type": "string"
           },
           "from": {
            "type": "string"
           },
           "value": {
            "type": "string"
           }
          }
         },
         "inputToken": {
          "type": "string",
          "description": "Address of the input token for this step"
         },
         "inputAmount": {
          "type": "string",
          "description": "Input amount in token base units for this step"
         }
        }
       },
       "description": "Ordered list of transaction steps to simulate sequentially"
      },
      "sender": {
       "type": "string",
       "description": "Address of the sender executing all steps"
      },
      "recipient": {
       "type": "string",
       "description": "Optional recipient address"
      }
     }
    },
    "type": {
     "type": "string",
     "const": "http"
    },
    "method": {
     "enum": [
      "POST"
     ],
     "type": "string"
    },
    "bodyType": {
     "enum": [
      "json",
      "form-data",
      "text"
     ],
     "type": "string"
    }
   },
   "additionalProperties": false
  },
  "output": {
   "type": "object",
   "required": [
    "type"
   ],
   "properties": {
    "type": {
     "type": "string"
    },
    "example": {
     "type": "object"
    }
   }
  }
 }
}
```

## Response schema (JSON Schema)

```json
{
 "type": "json",
 "example": {
  "steps": [
   {
    "gasUsed": "46109",
    "success": true,
    "stepIndex": 0
   },
   {
    "gasUsed": "152847",
    "success": true,
    "stepIndex": 1
   }
  ],
  "success": true,
  "aggregate": {
   "gasCost": "5968680000000000",
   "gasUsed": "198956",
   "success": true,
   "inputTokens": [
    {
     "token": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
     "amount": "100000000",
     "standard": "erc20"
    }
   ],
   "assetChanges": [
    {
     "token": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
     "amount": "100000000",
     "standard": "erc20",
     "direction": "sent"
    },
    {
     "token": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
     "amount": "32450000000000000",
     "standard": "erc20",
     "direction": "received"
    }
   ],
   "outputTokens": [
    {
     "token": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
     "amount": "32450000000000000",
     "standard": "erc20"
    }
   ],
   "tokenMetadata": {
    "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48": {
     "name": "USD Coin",
     "symbol": "USDC",
     "decimals": 6
    },
    "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2": {
     "name": "Wrapped Ether",
     "symbol": "WETH",
     "decimals": 18
    }
   }
  }
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/portals-foresight-defi-batch-transaction-simulation-api-c391e6d7/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from foresight.portals.fi](https://www.zero.xyz/host/foresight.portals.fi/llms.txt)
