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

# dApp Implementation

> Describes the protocol implementation for the User/dApp

<Steps>
  <Step title="Derive secret and hashlock">
    Using the [recoverable secret generation mechanism](/protocol/atomic-swaps-secret_gen), derive a secret from the user's wallet signature, source chain, destination chain, and timelock parameters. Hash the secret to create the hashlock.
  </Step>

  <Step title="Lock funds on source chain">
    Call the `lock()` function to lock funds with the derived hashlock and a timelock of [$T + \Delta$](/protocol-spec/model/#standard-flow).
  </Step>

  <Step title="Monitor the destination chain">
    * Watch for the `TokenLocked` event or use the `Id` on the destination chain by calling `getDetails()`.
    * Verify that the `hashlock` of the `HTLC` on the destination chain matches your derived hashlock and provides sufficient time, ensuring it is at least [$T + 2\Delta$](/protocol-spec/model/#standard-flow).

    <Note>
      The state of the destination chain should be read from a Light Client if one exists; if not, it should be read from multiple RPC providers.
    </Note>
  </Step>

  <Step title="Transmit signature with secret to Solver">
    Sign a message containing the derived secret and transmit this signed message to the Solver or any available actor. This allows them to use the secret to unlock funds on both chains without requiring further user interaction.

    <Note>
      This signature transmission can happen via off-chain channels (WebSocket, API, etc.). The signature includes the actual secret, which the Solver can now use.
    </Note>
  </Step>

  <Step title="Solver uses secret to release funds">
    The Solver reveals the secret on the destination chain to unlock the user's funds and on the source chain to claim their own funds. Both the user and Solver can now complete their side of the transaction.
  </Step>
</Steps>

<Warning>
  [Edge Case: Solver Fails to Act on the User’s Commitment/Intent](/protocol-spec/edge-cases#solver-fails-to-act-on-the-users-commitment-intent)

  * Wait for the `timelock` to expire.
  * Call `refund()` on the source chain to reclaim your funds.
</Warning>

<Warning>
  [Edge Case: Solver Fails to Release Any Funds](/protocol-spec/edge-cases#solver-fails-to-release-any-funds)

  * Wait for the `timelock` to expire.
  * Call `refund()` on the source chain to reclaim your funds.
</Warning>

<Warning>
  [Edge Case: Solver Fails to Release the User’s Funds](/protocol-spec/edge-cases#solver-fails-to-release-the-users-funds)

  * If funds are not released on the destination chain, watch the source chain for the `TokenRedeemed` event (or `getDetails()` function).
  * Once detected, capture the `secret` and call `redeem()` on the destination chain.
</Warning>
