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

# Set Loan Approvals

> Switch approve-only loans on or off for a market

Builds the next transaction that switches [approve-only loans](https://docs.trusset.org/endpoints/lending/loan-approvals.md) on or off, and confirms it on a second call. Trusset never signs: the market admin signs the calldata this route returns.

Switching on takes up to two signatures:

1. `CREATE_APPROVALS` builds the market's approvals contract. The answer carries `remaining: 1`.
2. Call again with `enabled: true` for `SWITCH_ON`, which names the approvals contract on the market.

Switching off is one signature, `SWITCH_OFF`.

If approve-only loans were only requested at deployment and never switched on, `enabled: false` clears the request without a transaction. The answer is then `action: NONE` with `cleared: true`.

## Who can call

The market admin, the holder of `DEFAULT_ADMIN_ROLE`.

## Path Parameters

**marketId** `string` *required*

The market's record ID on your instance.

## Body Parameters

Send exactly one of `enabled` or `txHash`.

**enabled** `boolean`

`true` to switch approve-only loans on, `false` to switch them off.

**signerAddress** `string`

The wallet that will sign.

**txHash** `string`

Hash of the transaction you broadcast for the step this route built. Send it to confirm the step.

## Response Fields

**data** `object`

**action** `string`

`SIGN_TRANSACTION`, or `NONE` when a request was cleared without a transaction. Returned when `txHash` is omitted.

**step** `string`

`CREATE_APPROVALS`, `SWITCH_ON` or `SWITCH_OFF`.

**transaction** `object`

`{ to, data }`, the unsigned transaction. Returned when `txHash` is omitted.

**functionName** `string`

`createLoanApprovals` or `setLoanApprovals`. Returned when `txHash` is omitted.

**signer** `string`

The wallet that signs. When confirming, the wallet that sent the transaction.

**requiredRole** `string | null`

`DEFAULT_ADMIN_ROLE`, or `null`. Returned when `txHash` is omitted.

**approvals** `string`

The approvals contract the step names. Present when the step carries one.

**remaining** `number`

`1` when another signature follows this step, `0` otherwise.

**confirmWith** `object`

`{ endpoint, field }`: the call that confirms this transaction, and `txHash` as the body field that carries the hash. Returned when `txHash` is omitted.

**cleared** `boolean`

`true` when the request made at deployment was cleared without a transaction.

**mode** `object`

The mode after the change. See [Get Loan Approvals](https://docs.trusset.org/endpoints/lending/get-loan-approvals.md#response-fields). Returned when confirming, and when a request was cleared.

**txHash** `string`

Transaction hash. Returned when confirming.

**blockNumber** `number`

Block the transaction was mined in. Returned when confirming.

**marketId** `string`

The market's record ID on your instance.

```json 200 First signature theme={null}
{
  "success": true,
  "data": {
    "action": "SIGN_TRANSACTION",
    "step": "CREATE_APPROVALS",
    "transaction": {
      "to": "0x3a9f1c7e5b2d8046f1e3c5a7b9d0e2f4a6c8b1d3",
      "data": "0x..."
    },
    "functionName": "createLoanApprovals",
    "signer": "0x7712db30a7b4ffd9c445793089118b60e56d752a",
    "requiredRole": null,
    "remaining": 1,
    "confirmWith": {
      "endpoint": "POST /lending-external-securities-v2/api/markets/cmwfk2h7x0003jw9w4q8b2n1c/loan-approvals",
      "field": "txHash"
    },
    "marketId": "cmwfk2h7x0003jw9w4q8b2n1c"
  },
  "error": null
}
```

```json 200 Second signature theme={null}
{
  "success": true,
  "data": {
    "action": "SIGN_TRANSACTION",
    "step": "SWITCH_ON",
    "transaction": {
      "to": "0x41b9c4d5dee70a5e3682094462e5065275e728a9",
      "data": "0x..."
    },
    "functionName": "setLoanApprovals",
    "signer": "0x7712db30a7b4ffd9c445793089118b60e56d752a",
    "requiredRole": "DEFAULT_ADMIN_ROLE",
    "approvals": "0x5d2e8c1a7f4b3960e2d1c8a7b6f5e4d3c2b1a098",
    "remaining": 0,
    "confirmWith": {
      "endpoint": "POST /lending-external-securities-v2/api/markets/cmwfk2h7x0003jw9w4q8b2n1c/loan-approvals",
      "field": "txHash"
    },
    "marketId": "cmwfk2h7x0003jw9w4q8b2n1c"
  },
  "error": null
}
```

```json 200 Confirmed theme={null}
{
  "success": true,
  "data": {
    "txHash": "0x9f2c41d8b7e05a3164c2870fbd935e1a4c7802db6135ea9048f7c21b5d3ea41b",
    "signer": "0x7712db30a7b4ffd9c445793089118b60e56d752a",
    "blockNumber": 6789012,
    "step": "SWITCH_ON",
    "remaining": 0,
    "mode": {
      "supported": true,
      "available": true,
      "enabled": true,
      "requested": false,
      "approvals": "0x5d2e8c1a7f4b3960e2d1c8a7b6f5e4d3c2b1a098",
      "canonical": true,
      "upgradeRequired": false,
      "approverRole": "0x46f54e51673dd785402ec1df75a85f2b1da1abc02695cc95d95578f830f58153",
      "maxValidHours": 696,
      "viewer": {
        "isBank": true,
        "isAdmin": true,
        "approverWallets": [
          "0x7712db30a7b4ffd9c445793089118b60e56d752a"
        ]
      }
    },
    "marketId": "cmwfk2h7x0003jw9w4q8b2n1c"
  },
  "error": null
}
```

```json 200 Request cleared theme={null}
{
  "success": true,
  "data": {
    "action": "NONE",
    "cleared": true,
    "mode": {
      "supported": true,
      "available": true,
      "enabled": false,
      "requested": false,
      "approvals": null,
      "canonical": null,
      "upgradeRequired": false,
      "approverRole": "0x46f54e51673dd785402ec1df75a85f2b1da1abc02695cc95d95578f830f58153",
      "maxValidHours": 696,
      "viewer": {
        "isBank": true,
        "isAdmin": true,
        "approverWallets": [
          "0x7712db30a7b4ffd9c445793089118b60e56d752a"
        ]
      }
    },
    "marketId": "cmwfk2h7x0003jw9w4q8b2n1c"
  },
  "error": null
}
```

## Error Codes

| Code | HTTP | Cause |
| - | - | - |
| `NOT_MARKET_ADMIN` | `403` | No verified wallet of your instance holds `DEFAULT_ADMIN_ROLE` on the market |
| `SIGNER_NOT_AUTHORIZED` | `403` | `signerAddress` is not a wallet that may sign this step |
| `MODE_CHANGE_NOT_INSTANCE_BOUND` | `403` | The transaction was signed by a wallet that is not verified for your instance |
| `MARKET_PENDING_CURATOR` | `409` | The market has no lender of record yet |
| `MARKET_UPGRADE_REQUIRED` | `409` | The market runs an implementation from before this feature. Its admin upgrades it through the seven-day notice first |
| `LOAN_APPROVALS_CURRENT` | `409` | Approve-only loans are already in the state you asked for. Nothing to sign |
| `LOAN_APPROVALS_NOT_AVAILABLE` | `409` | The network does not carry the approvals factory yet |
| `MODE_CHANGE_WOULD_REVERT` | `409` | The transaction would revert as it stands, so nothing was built |
| `CHAIN_UNAVAILABLE` | `503` | The chain could not be read just now |


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