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

# Build funding instructions for a settlement leg

> Requires the `settlements:read` scope (as an M2M scope or a user permission).

Construct the approve and deposit transactions for one leg, addressed by its stable leg id, from the escrow's registered terms as observed at one block: the approval covers the registered amount plus the registered depositor fee, and the deposit calldata embeds the leg's deposit secret. Served only for a leg delivered by a party of the calling environment; any other leg is answered as not found. Refused while the settlement is outside its deposit window, once the leg is deposited, past the deadline, or when the contract's registered terms do not match KeyStone's record. A 200 constructs only: nothing is signed, submitted, deposited or settled, and the contract decides the deposit when the transaction is mined. Served with Cache-Control: private, no-store.



## OpenAPI

````yaml /api-reference/openapi.json post /v1/settlements/{settlement_id}/legs/{leg_id}/funding-instructions
openapi: 3.1.0
info:
  title: Keystone API
  description: Settlement orchestration API for tokenized Real-World Assets (RWAs).
  version: 0.9.0
  x-keystone-api-contract-version: 0.9.0
  x-keystone-source-revision: c094c5ec38de81d550cde98e6366efaac99cffea
servers:
  - url: https://api-staging.keystoneos.xyz
    description: Staging (sandbox)
  - url: https://api.keystoneos.xyz
    description: Production
security:
  - bearerAuth: []
tags:
  - name: health
    description: Health and version checks.
  - name: platforms
    description: Register and manage your platform profile.
  - name: environments
    description: Manage platform environments (sandbox, production).
  - name: settlement-templates
    description: View and manage settlement templates.
  - name: settlements
    description: Initiate, monitor, and manage settlements.
  - name: sessions
    description: Create and manage browser-safe session tokens for frontend widgets.
  - name: instructions
    description: Submit and manage settlement instructions.
  - name: invitations
    description: Invite team members to your platform.
  - name: members
    description: Manage platform team members and roles.
  - name: webhooks
    description: Configure webhook endpoints for real-time event notifications.
  - name: security
    description: IP allowlisting and API access controls.
  - name: activity
    description: Audit trail of platform actions.
  - name: dashboard
    description: Dashboard metrics and statistics.
  - name: callbacks
    description: Provider callback handlers (internal).
  - name: alchemy-webhooks
    description: Alchemy blockchain event webhooks (internal).
  - name: chains
    description: Supported blockchain networks for settlement.
  - name: admin
    description: KeyStone internal administration endpoints.
  - name: admin-platforms
    description: Admin platform management.
  - name: admin-settlements
    description: Admin settlement oversight and intervention.
  - name: admin-compliance
    description: Admin compliance check management.
  - name: admin-activity
    description: Admin system-wide activity logs.
  - name: admin-webhooks
    description: Admin webhook diagnostics.
  - name: internal
    description: Keystone-internal worker endpoints.
  - name: internal-compliance
    description: Internal compliance engine endpoints.
paths:
  /v1/settlements/{settlement_id}/legs/{leg_id}/funding-instructions:
    post:
      tags:
        - settlements
      summary: Build funding instructions for a settlement leg
      description: >-
        Requires the `settlements:read` scope (as an M2M scope or a user
        permission).


        Construct the approve and deposit transactions for one leg, addressed by
        its stable leg id, from the escrow's registered terms as observed at one
        block: the approval covers the registered amount plus the registered
        depositor fee, and the deposit calldata embeds the leg's deposit secret.
        Served only for a leg delivered by a party of the calling environment;
        any other leg is answered as not found. Refused while the settlement is
        outside its deposit window, once the leg is deposited, past the
        deadline, or when the contract's registered terms do not match
        KeyStone's record. A 200 constructs only: nothing is signed, submitted,
        deposited or settled, and the contract decides the deposit when the
        transaction is mined. Served with Cache-Control: private, no-store.
      operationId: >-
        build_funding_instructions_for_leg_v1_settlements__settlement_id__legs__leg_id__funding_instructions_post
      parameters:
        - name: settlement_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
            title: Settlement Id
        - name: leg_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
            title: Leg Id
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FundingInstructionsRead'
        '404':
          description: Settlement not found, or the leg is not one this environment funds.
        '409':
          description: >-
            The settlement is outside its deposit window
            (FUNDING_WINDOW_CLOSED), the deadline has passed
            (FUNDING_DEADLINE_PASSED), the leg is already deposited
            (LEG_ALREADY_DEPOSITED), or the escrow's registered terms differ
            from KeyStone's record (ESCROW_REGISTRATION_MISMATCH).
        '422':
          description: >-
            The leg is a receive leg, is off-chain, is on a chain this
            deployment's escrow does not serve, has no deposit secret, or its
            party holds no usable wallet.
        '503':
          description: The escrow could not be read; no instructions are constructed blind.
components:
  schemas:
    FundingInstructionsRead:
      properties:
        kind:
          type: string
          const: escrow_deposit
          title: Kind
        settlement_id:
          type: string
          format: uuid
          title: Settlement Id
        leg_id:
          type: string
          format: uuid
          title: Leg Id
        leg_index:
          type: integer
          title: Leg Index
          description: The canonical ordinal the contract keys the leg by.
        chain_id:
          type: integer
          title: Chain Id
        escrow_address:
          type: string
          title: Escrow Address
          description: The KeystoneSettlement contract holding the registration.
        token_address:
          type: string
          title: Token Address
        sender:
          type: string
          title: Sender
          description: >-
            The wallet the deposit commitment binds. Both transactions must be
            sent from it.
        amount:
          type: string
          title: Amount
          description: The registered leg amount, in base units.
        depositor_fee:
          type: string
          title: Depositor Fee
          description: >-
            The additive fee registered on the leg, in base units; the depositor
            pays it on top.
        total:
          type: string
          title: Total
          description: >-
            amount plus depositor_fee: what depositLeg pulls and what the
            approval covers.
        transactions:
          items:
            $ref: '#/components/schemas/FundingTransactionRead'
          type: array
          title: Transactions
          description: In submission order.
        deadline:
          $ref: '#/components/schemas/FundingDeadlineRead'
        observation:
          $ref: '#/components/schemas/EscrowObservationRead'
        wait_for:
          items:
            $ref: '#/components/schemas/WaitStepRead'
          type: array
          title: Wait For
          description: What to wait for after submitting, in order.
        constructed_only:
          type: boolean
          const: true
          title: Constructed Only
          description: 'Always true: a 200 constructs, it submits nothing.'
        meaning:
          type: string
          title: Meaning
      type: object
      required:
        - kind
        - settlement_id
        - leg_id
        - leg_index
        - chain_id
        - escrow_address
        - token_address
        - sender
        - amount
        - depositor_fee
        - total
        - transactions
        - deadline
        - observation
        - wait_for
        - constructed_only
        - meaning
      title: FundingInstructionsRead
      examples:
        - amount: '5000'
          chain_id: 84532
          constructed_only: true
          deadline:
            at: '2026-09-17T12:00:00Z'
            chain_timeout_at: 1789560000
            meaning: >-
              The deposit transaction must be mined in a block whose timestamp
              is strictly before the contract's timeoutAt. At or after it the
              contract reverts every deposit and the timeout claim takes over.
          depositor_fee: '25'
          escrow_address: '0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512'
          kind: escrow_deposit
          leg_id: 6f1c2b3a-4d5e-6f70-8192-a3b4c5d6e7f8
          leg_index: 1
          meaning: >-
            Constructed from the registered terms as observed; nothing was
            signed or submitted. Submission and the deposit it produces remain
            the sender's, and the contract decides them when the transaction is
            mined.
          observation:
            block_hash: 0x5a5a...
            block_number: 31337000
            block_timestamp: 1789556400
            chain_id: 84532
            escrow_address: '0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512'
            meaning: >-
              The contract's answer at this block, the latest the node served
              when asked. It is an observation, not finality: a later block can
              differ.
            observed_at: '2026-09-16T12:00:00Z'
          sender: '0x2222222222222222222222222222222222222222'
          settlement_id: 550e8400-e29b-41d4-a716-446655440000
          token_address: '0x036CbD53842c5426634e7929541eC2318f3dCF7e'
          total: '5025'
          transactions:
            - calldata: 0x095ea7b3...
              description: approve(escrow, 5025) on the leg's token, from the sender.
              purpose: approve
              to: '0x036CbD53842c5426634e7929541eC2318f3dCF7e'
              value: '0'
            - calldata: 0x8a1b2c3d...
              description: >-
                depositLeg(settlementId, 1, secret) on the escrow, from the
                sender, after the approval is mined.
              purpose: deposit
              to: '0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512'
              value: '0'
          wait_for:
            - description: A mined receipt with status 1 for the deposit transaction.
              stage: receipt
            - description: >-
                The leg reads back as deposited from the contract, and the leg's
                status becomes locked on the settlement read once KeyStone
                records the LegDeposited event.
              stage: deposit_observed
            - description: >-
                The settlement leaves its deposit window on the settlement read:
                SETTLED once every leg is deposited and the compliance gate is
                clear, or TIMED_OUT if the deadline passes first.
              stage: settlement_progress
    FundingTransactionRead:
      properties:
        purpose:
          type: string
          enum:
            - approve
            - deposit
          title: Purpose
        to:
          type: string
          title: To
          description: The contract to send the transaction to.
        calldata:
          type: string
          title: Calldata
          description: >-
            ABI-encoded calldata. The deposit calldata embeds the leg's deposit
            secret.
        value:
          type: string
          title: Value
          description: Native value to attach, in wei, as an integer string; always 0.
        description:
          type: string
          title: Description
      type: object
      required:
        - purpose
        - to
        - calldata
        - value
        - description
      title: FundingTransactionRead
    FundingDeadlineRead:
      properties:
        at:
          type: string
          format: date-time
          title: At
          description: The stored escrow deadline.
        chain_timeout_at:
          type: integer
          title: Chain Timeout At
          description: The contract's timeoutAt at the observed block, in Unix seconds.
        meaning:
          type: string
          title: Meaning
      type: object
      required:
        - at
        - chain_timeout_at
        - meaning
      title: FundingDeadlineRead
    EscrowObservationRead:
      properties:
        chain_id:
          type: integer
          title: Chain Id
          description: The chain the observed contract is bound on.
        escrow_address:
          type: string
          title: Escrow Address
          description: The KeystoneSettlement contract that answered.
        block_number:
          type: integer
          title: Block Number
        block_hash:
          type: string
          title: Block Hash
        block_timestamp:
          type: integer
          title: Block Timestamp
          description: >-
            The observed block's timestamp, in Unix seconds; the clock the
            contract's deadline is judged against.
        observed_at:
          type: string
          format: date-time
          title: Observed At
          description: When KeyStone took the observation, by its own clock.
        meaning:
          type: string
          title: Meaning
      type: object
      required:
        - chain_id
        - escrow_address
        - block_number
        - block_hash
        - block_timestamp
        - observed_at
        - meaning
      title: EscrowObservationRead
    WaitStepRead:
      properties:
        stage:
          type: string
          enum:
            - receipt
            - deposit_observed
            - settlement_progress
          title: Stage
        description:
          type: string
          title: Description
      type: object
      required:
        - stage
        - description
      title: WaitStepRead
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        Auth0 JWT access token. See
        [Authentication](/getting-started/authentication) for details.

````