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

# Sponsor a withdrawal

> Request, cancel, or finalize a collateral withdrawal with the facilitator paying gas.

`POST /withdraw`

A withdrawal has three steps, and `action` selects which one the facilitator submits to the `Treasury` and pays gas for:

* `request` opens a withdrawal request and starts its grace period. The user signs an EIP-712 authorization.
* `cancel` clears a pending request. The user signs an EIP-712 authorization.
* `finalize` pays out a request whose grace period has elapsed. It needs no signature, because the contract pays the user whoever submits it.

Every action applies to the user named in the request, never to the relayer. This works for ETH as well as tokens; ETH uses the zero address as `asset`.

`POST /withdraw/verify` takes the same body, runs every check without broadcasting, and answers with the [`/verify` response shape](https://docs.4mica.io/api-reference/facilitator/verify#responses).

## Request body

**network** `string`

CAIP-2 network ID. When omitted, the facilitator uses the first network it serves whose core accepts the asset. Send it.

**action** `string` *required*

**authorization** `object`

Required for `request` and `cancel`.

**authorization.user** `string`

**authorization.asset** `string`

**authorization.amount** `string`

`request` only. Base units.

**authorization.validAfter** `string`

**authorization.validBefore** `string`

**authorization.nonce** `string`

32 bytes as hex. Request and cancel authorizations share one nonce space.

**authorization.signature** `string`

The user's EIP-712 signature under the Treasury's domain.

**user** `string`

Required for `finalize`.

**asset** `string`

Required for `finalize`.

## Responses

Every request the facilitator can parse returns `200`. Read `success`.

**success** `boolean` *required*

**transaction** `string`

Transaction hash. Present on success, and on a failure that happened after broadcast.

**network** `string`

**user** `string`

The user the action applied to.

**asset** `string`

**amount** `string`

Present for `request` only.

**errorReason** `string`

A machine-readable reason code. Present on failure.

**errorMessage** `string`

**extra.retryable** `boolean`

Whether repeating the same request later may succeed. Present on failure.

```bash cURL theme={null}
curl -X POST "https://testnet.payment.4mica.io/withdraw" \
  -H "Content-Type: application/json" \
  -d '{
    "network": "eip155:84532",
    "action": "request",
    "authorization": {
      "user": "0x1111111111111111111111111111111111111111",
      "asset": "0xba50Cd2A20f6DA35D788639E581bca8d0B5d4D5f",
      "amount": "0x4c4b40",
      "validAfter": "0x0",
      "validBefore": "0x6b0f1a80",
      "nonce": "0x6666666666666666666666666666666666666666666666666666666666666666",
      "signature": "0xUserSignature"
    }
  }'
```

```bash Finalize theme={null}
curl -X POST "https://testnet.payment.4mica.io/withdraw" \
  -H "Content-Type: application/json" \
  -d '{
    "network": "eip155:84532",
    "action": "finalize",
    "user": "0x1111111111111111111111111111111111111111",
    "asset": "0xba50Cd2A20f6DA35D788639E581bca8d0B5d4D5f"
  }'
```

```javascript title="Fetch" theme={null}
const response = await fetch("https://testnet.payment.4mica.io/withdraw", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ network: "eip155:84532", action: "request", authorization }),
});
console.log(await response.json());
```

```python Python theme={null}
import requests
body = {"network": "eip155:84532", "action": "request", "authorization": authorization}
print(requests.post("https://testnet.payment.4mica.io/withdraw", json=body).json())
```

```json 200 Submitted theme={null}
{
  "success": true,
  "transaction": "0x9999999999999999999999999999999999999999999999999999999999999999",
  "network": "eip155:84532",
  "user": "0x1111111111111111111111111111111111111111",
  "asset": "0xba50cd2a20f6da35d788639e581bca8d0b5d4d5f",
  "amount": "5000000"
}
```

```json 200 Refused theme={null}
{
  "success": false,
  "errorReason": "simulation_reverted",
  "errorMessage": "withdrawal would revert: GracePeriodNotElapsed",
  "extra": { "retryable": false }
}
```

## Reason codes

| `errorReason` | Meaning |
| - | - |
| `invalid_payload` | The body is malformed. |
| `invalid_signature` | The signature is malformed or does not recover to `user`. |
| `authorization_expired` | The authorization's validity window has ended. |
| `authorization_not_yet_valid` | The authorization's validity window has not started. |
| `nonce_already_used` | The authorization was already spent. |
| `simulation_reverted` | The call would revert, for example a `finalize` before the grace period has elapsed. |
| `sponsorship_unavailable` | The facilitator is not set up to sponsor gas on this network. |
| `relayer_underfunded` | The relayer cannot pay for gas right now. |
| `gas_ceiling_exceeded` | The call needs more gas than the facilitator sponsors. |
| `rate_limited` | Too many requests. Retry shortly. |
| `duplicate_in_flight` | The same authorization is already being submitted. |
| `chain_unavailable` | The chain, or this network's core or gas relayer, could not be reached. Retry shortly. |
| `broadcast_failed` | The transaction could not be broadcast. |
| `settlement_pending` | The transaction was broadcast but its receipt could not be read. `transaction` carries the hash. |
| `invalid_transaction_state` | The transaction was mined and reverted. |

## Status codes

| Code | Description |
| - | - |
| `200` | The facilitator processed the request. Check `success`. |
| `400`, `415`, `422` | The body is not JSON the endpoint can parse. The response is plain text. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.