# Send Statement

Source: https://docs.formance.com/v3.2/modules/flows/stages/send

Stack: v3.2

The `send` statement is the main and most powerful stage of the Workflow definition. It moves funds between ledger accounts, wallets, and payment service providers (PSPs), handling the underlying ledger transactions automatically.

A `send` stage has three attributes:

- `source` — where the funds come from
- `destination` — where the funds go
- `amount` — how much, and which asset

Both `source` and `destination` may reference a ledger account, a wallet, or a payment. Skeleton:

```yaml
---
stages:
- send:
    source:
      # ...
    destination:
      # ...
    amount:
      amount: 100
      asset: "EUR/2"
```

## Compatibility matrix

|                      | ↘ Ledger account | ↘ Wallet | ↘ Payment |
| -------------------- | ---------------- | -------- | --------- |
| ↗ **Ledger account** | ✅                | ✅        | ✅         |
| ↗ **Wallet**         | ✅                | ✅        | ✅         |
| ↗ **Payment**        | ✅                | ✅        | ❌         |

Payment destinations work with **any PSP connector configured in the Payments service** — Stripe, Wise, Modulr, Banking Circle, Currency Cloud, Mangopay, and the rest. Validation is delegated to Payments, so new connectors light up here automatically.

## Source types

### Ledger account

Reference a ledger account by `id` (the address) and `ledger` (the ledger name):

```yaml
source:
  account:
    id: "users:42"
    ledger: "flows-demo-001"
```

For cross-ledger flows you can also customize the intermediate "bridge" account via `throughAccount` and allow it to go negative via `allowOverdraft`:

| Field            | Type   | Required | Default   | Description                                            |
| ---------------- | ------ | -------- | --------- | ------------------------------------------------------ |
| `id`             | string | yes      | —         | Ledger account address                                 |
| `ledger`         | string | yes      | —         | Ledger name                                            |
| `throughAccount` | string | no       | `"world"` | Intermediate account for cross-ledger or payment flows |
| `allowOverdraft` | bool   | no       | `false`   | Allow unbounded overdraft on the source account        |

```yaml
source:
  account:
    id: "users:123"
    ledger: "main"
    throughAccount: "liabilities:pending"
    allowOverdraft: true
```

### Wallet

Reference a wallet by either `id` or `name`. `balance` selects a specific balance (defaults to `main`):

```yaml
source:
  wallet:
    id: "22d5de50-b5ef-407d-9a03-9e4fc36356f8"
    balance: "main"   # optional
```

### Payment

Reference an existing payment (a payin) by `id`:

```yaml
source:
  payment:
    id: "22d5de50-b5ef-407d-9a03-9e4fc36356f8"
```

The payment is "ingested" — moved into a ledger as an intermediate step — before being transferred to the destination. By default this uses an internal orchestration ledger; you can override the ingestion target:

| Field            | Type   | Required | Default                        | Description                                   |
| ---------------- | ------ | -------- | ------------------------------ | --------------------------------------------- |
| `id`             | string | yes      | —                              | Payment ID from the Payments service          |
| `ledger`         | string | no       | `"orchestration-000-internal"` | Ledger for payment ingestion                  |
| `holdingAccount` | string | no       | `"payment:{id}"`               | Account where ingested funds are held         |
| `throughAccount` | string | no       | `"world"`                      | Source account for the ingestion transaction  |
| `allowOverdraft` | bool   | no       | `false`                        | Allow unbounded overdraft on `throughAccount` |

```yaml
source:
  payment:
    id: "${paymentID}"
    ledger: "main"
    holdingAccount: "assets:stripe:held"
    throughAccount: "assets:stripe:incoming"
    allowOverdraft: true
```

See [Payment ingestion](#payment-ingestion) below for the full picture.

## Destination types

### Ledger account

```yaml
destination:
  account:
    id: "users:42"
    ledger: "flows-demo-001"
```

Same `throughAccount` / `allowOverdraft` options as ledger-account sources — they govern the intermediate account used on cross-ledger transfers:

```yaml
destination:
  account:
    id: "merchants:456"
    ledger: "main"
    throughAccount: "assets:incoming"
    allowOverdraft: true
```

### Wallet

```yaml
destination:
  wallet:
    id: "22d5de50-b5ef-407d-9a03-9e4fc36356f8"
```

### Payment

Unlike source payments, destination payments aren't referenced by ID (the payment doesn't exist yet). Instead, you tell the stage which PSP connector to use:

```yaml
destination:
  payment:
    psp: "stripe"
    type: "PAYOUT"
    sourceAccount: "${sourceAccountID}"
    metadata: "stripeConnectID"
```

The full field set:

| Field               | Type   | Required | Default      | Description                                                             |
| ------------------- | ------ | -------- | ------------ | ----------------------------------------------------------------------- |
| `psp`               | string | yes      | —            | PSP connector name (`"stripe"`, `"wise"`, `"modulr"`, …)                |
| `type`              | string | no       | `"TRANSFER"` | `"TRANSFER"` or `"PAYOUT"`                                              |
| `metadata`          | string | no       | —            | Account-metadata key carrying the destination PSP account ID            |
| `sourceAccount`     | string | no       | —            | Explicit PSP source account ID for the transfer                         |
| `connectorID`       | string | no       | —            | Specific connector ID (when multiple connectors of the same type exist) |
| `waitingValidation` | bool   | no       | `false`      | Whether to wait for manual validation before settling                   |

The ledger or wallet debit happens **before** the PSP transfer is initiated. On PSP failure the workflow is left in a consistent state — funds remain debited from the source until the workflow handles the failure explicitly.

## Cross-ledger transfers

When source and destination live on different ledgers, the `throughAccount` field on each side controls the intermediate "bridge" account used.

### Same ledger (direct transfer)

```yaml
send:
  source:
    account: { id: "users:123", ledger: "main" }
  destination:
    account: { id: "merchants:456", ledger: "main" }
```

A single transaction posts on `main` from `users:123` to `merchants:456`.

### Different ledgers (bridge transfer)

```yaml
send:
  source:
    account:
      id: "users:sender"
      ledger: "ledger1"
      throughAccount: "bridge:outbound"
  destination:
    account:
      id: "merchants:receiver"
      ledger: "ledger2"
      throughAccount: "bridge:inbound"
      allowOverdraft: true
```

Two transactions post:

1. On `ledger1`: `users:sender` → `bridge:outbound`
2. On `ledger2`: `bridge:inbound` → `merchants:receiver`

`bridge:inbound` may need `allowOverdraft: true` if it isn't pre-funded.

## The `allowOverdraft` field

By default the Ledger requires source accounts to have sufficient funds. The special `"world"` account has unbounded overdraft and is used by default for bridge transactions — which is why the cross-ledger example above works without explicit overdraft when the default `world` bridge is in play.

When you point `throughAccount` at a custom account, you may need `allowOverdraft: true` to let the account go negative. The generated Numscript carries an `allowing unbounded overdraft` clause.

Where overdraft applies per flow

| Flow                            | Transaction                           | Overdraft applied to |
| ------------------------------- | ------------------------------------- | -------------------- |
| Account → Payment               | `source.id → throughAccount`          | `source.id`          |
| Payment → Account               | `throughAccount → holdingAccount`     | `throughAccount`     |
| Account → Wallet (cross-ledger) | `source.id → throughAccount`          | `source.id`          |
| Wallet → Account (cross-ledger) | `throughAccount → destination.id`     | `throughAccount`     |
| Account → Account (1st tx)      | `source.id → sourceThroughAccount`    | `source.id`          |
| Account → Account (2nd tx)      | `destThroughAccount → destination.id` | `destThroughAccount` |

### Example: liability tracking for payouts

```yaml
send:
  source:
    account:
      id: "users:${userID}"
      ledger: "main"
      throughAccount: "liabilities:payouts-pending"
      allowOverdraft: true
  destination:
    payment:
      psp: "stripe"
      type: "PAYOUT"
```

Posts as `users:{userID}` → `liabilities:payouts-pending` instead of `users:{userID}` → `world`, so the in-flight payout shows up on your liabilities account until the PSP confirms settlement.

## Payment ingestion

When the source is a payment, the funds are ingested into a ledger before being transferred to the destination. By default this happens on an internal orchestration ledger:

```
1. world → payment:{paymentID}   on orchestration-000-internal
2. payment:{paymentID} → world   on orchestration-000-internal (with metadata)
3. world → destination           on the destination ledger
```

To ingest directly into your own ledger and account scheme:

```yaml
source:
  payment:
    id: "${paymentID}"
    ledger: "main"
    holdingAccount: "assets:stripe:held"
    throughAccount: "assets:stripe:incoming"
    allowOverdraft: true
```

Produces:

```
1. assets:stripe:incoming → assets:stripe:held   on main
2. assets:stripe:held → destination              on main
```

## Complete examples

Ledger to payout with tracking

```yaml
name: "payout-with-tracking"
stages:
- send:
    source:
      account:
        id: "users:${userID}"
        ledger: "main"
        throughAccount: "liabilities:payouts-pending"
        allowOverdraft: true
    destination:
      payment:
        psp: "${psp}"
        type: "PAYOUT"
        sourceAccount: "${sourceAccountID}"
    amount:
      amount: "${amount}"
      asset: "${asset}"
```

Payment to account with custom ingestion

```yaml
name: "payin-custom-ingestion"
stages:
- send:
    source:
      payment:
        id: "${paymentID}"
        ledger: "main"
        holdingAccount: "assets:stripe:pending"
        throughAccount: "assets:stripe:bridge"
        allowOverdraft: true
    destination:
      account:
        id: "revenue:${merchantID}"
        ledger: "main"
    amount:
      amount: "${amount}"
      asset: "${asset}"
```

Cross-ledger with custom bridge accounts

```yaml
name: "cross-ledger-transfer"
stages:
- send:
    source:
      account:
        id: "users:${userID}"
        ledger: "users-ledger"
        throughAccount: "bridge:to-merchants"
    destination:
      account:
        id: "merchants:${merchantID}"
        ledger: "merchants-ledger"
        throughAccount: "bridge:from-users"
        allowOverdraft: true
    amount:
      amount: "${amount}"
      asset: "${asset}"
```
