FOR_EACH
FOR_EACH iterates over an array, spawning an independent subgraph execution for each item. All iterations run concurrently — the workflow only advances once all items have completed.
How it works
- Receives an
itemsarray from an upstream component - For each item, spawns a copy of the downstream subgraph
- Passes the current
itemas a data output to downstream components - Waits for all iterations to complete
- Aggregates results and passes control to the next stage
ARRAY_BUILDER (items: ["0xAddr1", "0xAddr2", "0xAddr3"])
│ items[]
▼
FOR_EACH
├── item: "0xAddr1" ──▶ GET_EVM_ACCOUNT_BALANCE
├── item: "0xAddr2" ──▶ GET_EVM_ACCOUNT_BALANCE (parallel)
└── item: "0xAddr3" ──▶ GET_EVM_ACCOUNT_BALANCE (parallel)
│
▼ (all complete)
Next stage
Inputs
| Port | Type | Description |
|---|---|---|
items | array | The array to iterate over. Each element becomes the item output for one iteration. |
Outputs
| Port | Type | Description |
|---|---|---|
item | any | Current iteration value — type is inferred from the items array element type |
index | number | Zero-based iteration index |
Examples
Check balances for a list of addresses
ARRAY_BUILDER
├─ item 0: "0xAddress1"
├─ item 1: "0xAddress2"
└─ item 2: "0xAddress3"
│ array output
▼
FOR_EACH
│ item (string — address)
▼
GET_EVM_ACCOUNT_BALANCE
├─ jsonRpcUrl: <from STRING_CONSTANT>
├─ tokenAddress: "0x000...000"
└─ account: <item>
Process a list of transactions
FOR_EACH (items: transaction_hashes[])
│ item (tx hash)
▼
WAIT_FOR_EVM_TRANSACTION
│ receipt
▼
API_CALL (report result to webhook)
Nested iteration (matrix)
FOR_EACH can be nested — the inner FOR_EACH runs for every item of the outer, creating a matrix of executions.
FOR_EACH (chains[])
└── FOR_EACH (addresses[])
└── GET_EVM_ACCOUNT_BALANCE
Concurrency and credits
All iterations run in parallel. A FOR_EACH over 100 items spawns 100 concurrent stages. Ensure your plan's concurrency limits accommodate this. Credit usage scales linearly with the number of items × the cost of the inner subgraph.
Design tips
- Aggregate results — use
ARRAY_BUILDERdownstream ofFOR_EACHto collect all iteration outputs into a single array for further processing - Error handling — if any iteration fails, the entire
FOR_EACHstage is marked failed. Use retry to re-run from the failed iteration subtree - Item type inference — connect the
itemsport from a typed output (e.g.ARRAY_BUILDER) and theitemoutput port will automatically inherit the element type in the visual builder