> For the complete documentation index, see [llms.txt](https://docs.cspr.cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cspr.cloud/x402-facilitator-api/settle.md).

# Settle

Validates a client's signed payment payload and, if valid, submits the payment transaction to the Casper Network. The facilitator's account pays the gas (motes) for the settlement deploy; the CEP-18 tokens are transferred from the payer to the payee via the `transfer_with_authorization` contract entry point.

```
POST /settle
```

## Request body

The request body has the same shape as [/verify](/x402-facilitator-api/verify.md).

| Property              | Type     | Required | Description                                               |
| --------------------- | -------- | -------- | --------------------------------------------------------- |
| `paymentPayload`      | `object` | Yes      | The signed payment payload submitted by the client.       |
| `paymentRequirements` | `object` | Yes      | The payment requirements declared by the resource server. |

See [Verify](/x402-facilitator-api/verify.md) for the full schema of `paymentPayload` and `paymentRequirements`.

## Response

The response always returns HTTP `200`. The `success` field indicates whether settlement succeeded.

| Property       | Type      | Description                                                           |
| -------------- | --------- | --------------------------------------------------------------------- |
| `success`      | `boolean` | `true` if the payment was settled on-chain, `false` otherwise.        |
| `transaction`  | `string`  | Casper deploy hash of the settlement transaction (64 hex characters). |
| `network`      | `string`  | CAIP-2 network identifier where the payment was settled.              |
| `payer`        | `string`  | Casper account hash of the payer.                                     |
| `errorReason`  | `string`  | Machine-readable error code, present when `success` is `false`.       |
| `errorMessage` | `string`  | Human-readable error description, present when `success` is `false`.  |

### Error codes

In addition to all [verification error codes](/x402-facilitator-api/verify.md#error-codes), the following codes may appear during settlement:

| Code                  | Description                                                                              |
| --------------------- | ---------------------------------------------------------------------------------------- |
| `network_mismatch`    | The facilitator has no signing key configured for the requested network.                 |
| `verification_failed` | The payload failed pre-settlement verification.                                          |
| `build_deploy_failed` | Failed to build the Casper `TransactionV1`.                                              |
| `sign_deploy_failed`  | Failed to sign the transaction with the facilitator's key.                               |
| `put_deploy_failed`   | Failed to submit the transaction to the Casper Network.                                  |
| `wait_deploy_failed`  | The transaction was submitted but confirmation timed out or returned an execution error. |

## Example

```bash
curl -X 'POST' \
  'https://x402-facilitator.cspr.cloud/settle' \
  -H 'authorization: 55f79117-fc4d-4d60-9956-65423f39a06a' \
  -H 'accept: application/json' \
  -H 'content-type: application/json' \
  -d '{
    "paymentPayload": {
      "x402Version": 2,
      "resource": {
          "url": "http://127.0.0.1:3002/api/data"
      },
      "accepted": {
          "scheme": "exact",
          "network": "casper:casper-test",
          "asset": "9824d60dc3a5c44a20b9fd260a412437933835b52fc683d8ae36e4ec2114843e",
          "amount": "10000",
          "payTo": "0000000000000000000000000000000000000000000000000000000000000000",
          "maxTimeoutSeconds": 300
      },
      "payload": {
        "signature": "01a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f601",
        "publicKey": "0176197d7191ce519ed043221956a2227921abf30364d4362970229027ec828f04",
        "authorization": {
          "from":        "00048a54220799a48171743407c086668bdcc788e2a31e4185fe52d0682634f888",
          "to":          "009e5669b070545e2b32bc66363b9d3d4390fca56bf52a05f1411b7fa18ca311c7",
          "value":       "10000",
          "validAfter":  "1710000000",
          "validBefore": "1710000900",
          "nonce":       "a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2"
        }
      }
    },
    "paymentRequirements": {
      "scheme": "exact",
      "network": "casper:casper-test",
      "payTo":  "009e5669b070545e2b32bc66363b9d3d4390fca56bf52a05f1411b7fa18ca311c7",
      "amount": "10000",
      "asset":  "9824d60dc3a5c44a20b9fd260a412437933835b52fc683d8ae36e4ec2114843e",
      "maxTimeoutSeconds": 900,
      "extra": {
        "name":     "Cep18x402",
        "version":  "1",
        "decimals": "2",
        "symbol":   "CSPR"
      }
    }
  }'
```

Successful settlement:

```json
{
  "success": true,
  "transaction": "88461218a5e972fcda1d764d7cc4edb2e0c3a538123b97890d484f43c55935f5",
  "network": "casper:casper-test",
  "payer": "00048a54220799a48171743407c086668bdcc788e2a31e4185fe52d0682634f888"
}
```

Failed settlement:

```json
{
  "success": false,
  "errorReason": "invalid_signature",
  "errorMessage": "signature verification failed",
  "transaction": "",
  "network": "casper:casper-test",
  "payer": ""
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cspr.cloud/x402-facilitator-api/settle.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
