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

# Credit Draw

> Draw credit against locked DeFi collateral via the Sprinter Credit API — lock, draw, repay, unlock

## Overview

The Sprinter Credit API lets you draw USDC credit against locked DeFi collateral. This guide walks through the full credit draw lifecycle: lock collateral, check your credit line, draw USDC, repay, and unlock.

<div style={{ paddingRight: "120px" }}>
  ```mermaid theme={null}
  flowchart TD
    A[User locks collateral] --> B[Credit line activated]
    B --> C[Draw USDC from credit line]
    C --> D[Use USDC — card funding, settlement, etc.]
    D --> E[Repay debt at end of billing cycle]
    E --> F[Unlock collateral]
  ```
</div>

<Info>
  This example demonstrates the core credit draw flow. For a card program integration, see the [Card Program Integration](/quickstart/card-program) quickstart.
</Info>

## Before You Start

If your use case requires drawing credit without user interaction (e.g. card authorizations, agent actions, automated strategies), you'll need a delegation model:

1. **Which account type?** EOA (existing wallet) or Smart Account — this affects how delegation is set up. See [Credit Accounts](/sprinter-credit/credit-accounts).
2. **Which operator model?** A [Credit Operator](/sprinter-credit/policy-engine#credit-operators) lets your backend act on the user's credit position without custody. See [Delegated Credit Draws](#delegated-credit-draws) below.

If users sign every transaction themselves, you can skip this and go straight to the integration steps.

## Integration Steps

<Steps>
  <Step title="Lock Collateral">
    Lock collateral to activate a credit line. A single `/lock` call handles everything — including optional wrapping into a yield-bearing earn vault.

    First, fetch available earn strategies from the protocol config:

    ```bash theme={null}
    curl -X GET https://api.sprinter.tech/credit/protocol
    ```

    This returns the credit configuration including a `strategies` field with available earn vaults and their IDs.

    Then lock collateral — add the `earn` param to auto-wrap into a vault in the same transaction:

    <Tabs>
      <Tab title="Lock + Earn Vault">
        ```bash theme={null}
        curl -X GET 'https://api.sprinter.tech/credit/accounts/0xUSER/lock?amount=1000000000000000000&asset=0xCOLLATERAL_TOKEN&earn=STRATEGY_ID'
        ```

        The `earn` parameter wraps the asset into a yield-bearing vault before locking — collateral earns while the credit line is active. Use a strategy ID from `/credit/protocol`.
      </Tab>

      <Tab title="Lock (No Vault)">
        ```bash theme={null}
        curl -X GET 'https://api.sprinter.tech/credit/accounts/0xUSER/lock?amount=1000000000000000000&asset=0xCOLLATERAL_TOKEN'
        ```

        Omit `earn` to lock the raw asset directly without wrapping into a vault.
      </Tab>
    </Tabs>

    Returns `{ calls: ContractCall[] }` — execute in the user's wallet. Once locked, the credit line is active.
  </Step>

  <Step title="Check Available Credit">
    Display `totalCollateralValue` (spendable credit) and `healthFactor` in your UI.

    ```bash theme={null}
    curl -X GET https://api.sprinter.tech/credit/accounts/0xUSER/info
    ```

    ```json theme={null}
    {
      "data": {
        "USDC": {
          "totalCollateralValue": "5000.00",
          "principal": "0",
          "interest": "0",
          "healthFactor": "Infinity",
          "dueDate": null
        }
      }
    }
    ```

    See [Credit Engine](/sprinter-credit/credit-engine) for how health factor and LTVs work.
  </Step>

  <Step title="Draw Credit">
    With collateral locked, draw USDC from the user's credit line. The `/draw` endpoint is a general-purpose credit draw — the `receiver` can be any address (your settlement address, a card issuer's deposit address, etc.).

    <Info>
      If your use case requires server-side draws without user interaction, you'll need a delegation model. See [Before You Start](#before-you-start).
    </Info>

    ```bash theme={null}
    curl -X GET 'https://api.sprinter.tech/credit/accounts/0xUSER/draw?amount=50000000&receiver=0xRECEIVER_ADDRESS'
    ```

    | Parameter  | Description                                                                                  |
    | ---------- | -------------------------------------------------------------------------------------------- |
    | `account`  | User's wallet address (borrower)                                                             |
    | `amount`   | USDC in lowest denomination (6 decimals — \$50 = `50000000`)                                 |
    | `receiver` | Address to receive the USDC (e.g. your settlement address, a card issuer's deposit contract) |

    Returns `{ calls: ContractCall[] }` — execute on-chain to deliver USDC to the receiver.

    <Info>
      A **0.50% origination fee** is deducted from each draw. See [Fees](/sprinter-credit/credit-engine#fees) for the full fee schedule.
    </Info>

    For card programs that need JIT draws inside an authorization webhook, see the webhook handler example:

    <Card title="Authorization Webhook Handler" icon="code" href="/quickstart/credit-draw/authorization-webhook">
      Complete TypeScript implementation showing how to wire `/draw` into a card authorization flow with signature validation, credit checks, and sub-2-second execution.
    </Card>
  </Step>

  <Step title="Repayment">
    Credit runs on a 30-day billing cycle with a 7-day grace period. Repay before the due date to avoid the **15% overdue APR**. See [Fees](/sprinter-credit/credit-engine#fees).

    <Tabs>
      <Tab title="Check Balance Owed">
        ```bash theme={null}
        curl -X GET https://api.sprinter.tech/credit/accounts/0xUSER/info
        # Returns: principal, interest, dueDate
        ```
      </Tab>

      <Tab title="Build Repayment">
        ```bash theme={null}
        curl -X GET 'https://api.sprinter.tech/credit/accounts/0xUSER/repay?amount=50000000'
        ```

        Returns `{ calls: ContractCall[] }`. Anyone can repay on behalf of any account, so you can run an automated repayment service.
      </Tab>
    </Tabs>
  </Step>

  <Step title="Unlock Collateral">
    When the user has zero outstanding debt:

    ```bash theme={null}
    curl -X GET 'https://api.sprinter.tech/credit/accounts/0xUSER/unlock?amount=1000000000000000000&asset=0xCOLLATERAL_TOKEN'
    ```

    Returns `{ calls: ContractCall[] }`. Execute in the user's wallet to return collateral.
  </Step>
</Steps>

## Delegated Credit Draws

Some use cases (like card authorizations) require credit draws without user interaction. This requires a [Credit Operator](/sprinter-credit/policy-engine#credit-operators) — a contract that lets your backend act on the user's credit position without custody. See [Credit Accounts](/sprinter-credit/credit-accounts) for choosing between EOA + Operator vs Smart Account. Two approaches:

<Tabs>
  <Tab title="Non-Custodial (Smart Accounts)">
    Users deploy a smart account (e.g. ERC-4337) that can execute draw transactions autonomously. The user retains full custody — the smart account automates signing based on pre-configured rules.

    **How it works:**

    1. User deploys or connects a smart account
    2. User configures a session key or module that authorizes your backend to call `/draw`
    3. At draw time, your backend submits the draw calldata through the smart account

    This is the most trust-minimized option — users never grant direct access to their credit line.
  </Tab>

  <Tab title="Operator Contract (Server-Side)">
    Your application deploys an [`ExclusiveOperator`](https://github.com/sprintertech/remote-collateral-contracts/blob/main/contracts/operator/ExclusiveOperator.sol) contract and sets your backend address as the authorized caller. Users opt in by setting this operator on their credit position and whitelisting your receiver address.

    **How it works:**

    1. Deploy an `ExclusiveOperator` with your backend address as the `caller`
    2. Users call `setOperator()` on the Credit Hub to opt in
    3. Users call `addCreditReceiver()` to whitelist your receiver address
    4. Your backend calls `openCreditLine(borrower, receiver, amount)` directly on-chain

    **Safety guarantees:**

    * The operator can **only** draw credit to whitelisted receivers — never withdraw collateral
    * Users can revoke access, but revocation has a **time delay** to prevent abuse during active billing cycles
    * Credit receivers must be explicitly whitelisted per user

    See the [Authorization Webhook Handler](/quickstart/credit-draw/authorization-webhook#delegated-credit-draws) for implementation details.
  </Tab>
</Tabs>

## Integration Notes

<AccordionGroup>
  <Accordion title="Signer Security" icon="key">
    Whether using smart accounts or the operator contract, the signing key that executes draws must be secured with HSM or cloud KMS (AWS KMS, GCP Cloud KMS) in production. Never store it in environment variables on shared infrastructure.
  </Accordion>

  <Accordion title="Receiver Address" icon="building-columns">
    The `receiver` in the draw call is the address that receives USDC. This could be your own settlement address, a card issuer's deposit contract, or any other address depending on your use case.
  </Accordion>

  <Accordion title="Fail Closed" icon="shield">
    Always decline if the draw cannot be confirmed on-chain. A declined transaction is recoverable; an unauthorized spend is not.
  </Accordion>

  <Accordion title="Health Monitoring" icon="heart-pulse">
    Poll `healthFactor` from the info endpoint and surface alerts in your UI. See [Risk Management](/sprinter-credit/risk-management) for liquidation thresholds and collateral tiers.
  </Accordion>
</AccordionGroup>

## Try It

Want to see the full credit draw lifecycle running end-to-end? The **Credit Draw Demo** executes every step above — lock, credit check, draw, repay, unlock — using real Sprinter API calls on Base. It also supports a dry-run mode for testing without on-chain transactions.

<Card title="Credit Draw Demo" icon="play" href="https://github.com/sprintertech/documentation/tree/main/examples/demo">
  Clone the repo, add a wallet with USDC on Base, and run `npm run ui` to launch the demo dashboard. See the README for full setup instructions.
</Card>

<Tip>
  You can also point an AI coding agent (like Claude) at the [Sprinter Credit API](/api-reference/sprinter/credit/get-credit-protocol-configuration) and your target receiver's API docs to generate a working proof of concept in minutes — the API is simple enough that an agent can wire up the full flow end-to-end.
</Tip>

## Related

<CardGroup cols={3}>
  <Card title="Card Program Integration" icon="credit-card" href="/quickstart/card-program">
    Add credit-backed card spending to your card program.
  </Card>

  <Card title="Credit Engine" icon="gear" href="/sprinter-credit/credit-engine">
    Health factor, LTVs, and liquidation mechanics.
  </Card>

  <Card title="Credit API Reference" icon="bolt" href="/api-reference/sprinter/credit/get-credit-protocol-configuration">
    Full API reference with interactive playground.
  </Card>
</CardGroup>
