# Walkthrough

Source: https://docs.settlemint.com/docs/operators/user-guides/system-addons/xvp-settlement/htlc/walkthrough
Follow a multi-party HTLC settlement where two DALP settlements use the same
hashlock to coordinate token and USDC flows across Ethereum and Polygon.




Two local DALP XvP settlements coordinate one cross-chain deal with a shared hashlock. DALP executes only the local flows on each settlement's chain. External flows describe the matching obligation on the other chain and help participants verify the deal before approval or reveal.

<Callout type="info" title="Prerequisites">
  This walkthrough assumes you know the HTLC terms hashlock, timelock, raw secret, and reveal. Read the [HTLC
  explanation](/docs/operators/user-guides/system-addons/xvp-settlement/htlc/htlc-explained) first if those terms are new.
</Callout>

## Scenario: Tokenized real estate sale [#scenario-tokenized-real-estate-sale]

A Builder sells 100 tokenized apartment tokens on Ethereum. Two Buyers pay USDC on Polygon, and a Notary receives a Polygon fee. The parties create one settlement on Ethereum for the property-token delivery and one settlement on Polygon for the USDC payment.

### Parties [#parties]

| Party       | Role in this walkthrough             | Local chain for approvals |
| ----------- | ------------------------------------ | ------------------------- |
| **Builder** | Sends property tokens                | Ethereum                  |
| **Buyer 1** | Sends payment and receives 50 tokens | Polygon                   |
| **Buyer 2** | Sends payment and receives 50 tokens | Polygon                   |
| **Notary**  | Receives the notary fee              | Polygon                   |

### Deal terms [#deal-terms]

| Item            | Amount                           |
| --------------- | -------------------------------- |
| Property price  | 500,000 USDC                     |
| Buyer 1's share | 250,000 USDC plus 2,500 USDC fee |
| Buyer 2's share | 250,000 USDC plus 2,500 USDC fee |
| Notary fee      | 5,000 USDC total                 |
| Property tokens | 100 APT-101 total                |

The same hashlock links both settlements:

| Value      | Example                                                              |
| ---------- | -------------------------------------------------------------------- |
| Raw secret | `closing-secret-apt-101-2025`                                        |
| Hashlock   | `0x920eda3b2f7ffb9adef73772ed5ef26ea12e8934c8ae5f2b24ec5a0c07ff8969` |

The raw secret is the value entered during reveal. The hashlock is the 32-byte `0x`-prefixed value stored on both settlements.

## Settlement structures [#settlement-structures]

### Ethereum settlement [#ethereum-settlement]

The Builder creates the Ethereum settlement because the Builder sends the property tokens on Ethereum.

| Field           | Value                                                                |
| --------------- | -------------------------------------------------------------------- |
| Local flow 1    | Builder sends 50 APT-101 to Buyer 1                                  |
| Local flow 2    | Builder sends 50 APT-101 to Buyer 2                                  |
| External flow 1 | Buyer 1 sends 250,000 USDC to Builder on Polygon                     |
| External flow 2 | Buyer 2 sends 250,000 USDC to Builder on Polygon                     |
| External flow 3 | Buyer 1 sends 2,500 USDC to Notary on Polygon                        |
| External flow 4 | Buyer 2 sends 2,500 USDC to Notary on Polygon                        |
| Hashlock        | `0x920eda3b2f7ffb9adef73772ed5ef26ea12e8934c8ae5f2b24ec5a0c07ff8969` |
| Timelock        | January 20, 2025 at 17:00 UTC                                        |
| Auto-execute    | Enabled for this walkthrough                                         |

### Polygon settlement [#polygon-settlement]

Buyer 1 creates the Polygon settlement because the Buyers send the USDC flows on Polygon. Buyer 2 still approves because Buyer 2 is also a local sender.

| Field           | Value                                                                |
| --------------- | -------------------------------------------------------------------- |
| Local flow 1    | Buyer 1 sends 250,000 USDC to Builder                                |
| Local flow 2    | Buyer 2 sends 250,000 USDC to Builder                                |
| Local flow 3    | Buyer 1 sends 2,500 USDC to Notary                                   |
| Local flow 4    | Buyer 2 sends 2,500 USDC to Notary                                   |
| External flow 1 | Builder sends 50 APT-101 to Buyer 1 on Ethereum                      |
| External flow 2 | Builder sends 50 APT-101 to Buyer 2 on Ethereum                      |
| Hashlock        | `0x920eda3b2f7ffb9adef73772ed5ef26ea12e8934c8ae5f2b24ec5a0c07ff8969` |
| Timelock        | January 19, 2025 at 17:00 UTC                                        |
| Auto-execute    | Enabled for this walkthrough                                         |

<Callout type="info" title="External flows do not execute the other chain">
  Each settlement executes only its local flows. The external flows make the matching obligation visible to
  participants. They do not transfer assets on the other chain.
</Callout>

<Callout type="info" title="Only local senders approve">
  On Ethereum, only the Builder approves because the Builder sends the local APT-101 tokens. On Polygon, Buyer 1 and
  Buyer 2 approve because those Buyers send the local USDC flows. Recipients do not approve.
</Callout>

## Balance tracking [#balance-tracking]

### Ethereum chain [#ethereum-chain]

| Step    | Action                                | Builder     | Buyer 1    | Buyer 2    | XvP contract |
| ------- | ------------------------------------- | ----------- | ---------- | ---------- | ------------ |
| Initial | No settlement action                  | 100 APT-101 | 0          | 0          | 0            |
| Create  | Builder creates settlement            | 100 APT-101 | 0          | 0          | 0            |
| Approve | Builder approves, settlement is Armed | 0           | 0          | 0          | 100 APT-101  |
| Execute | Secret is revealed on Ethereum        | 0           | 50 APT-101 | 50 APT-101 | 0            |

### Polygon chain [#polygon-chain]

| Step      | Action                                | Builder      | Notary     | Buyer 1      | Buyer 2      | XvP contract |
| --------- | ------------------------------------- | ------------ | ---------- | ------------ | ------------ | ------------ |
| Initial   | No settlement action                  | 0            | 0          | 252,500 USDC | 252,500 USDC | 0            |
| Create    | Buyer 1 creates settlement            | 0            | 0          | 252,500 USDC | 252,500 USDC | 0            |
| Approve 1 | Buyer 1 approves                      | 0            | 0          | 0            | 252,500 USDC | 252,500 USDC |
| Approve 2 | Buyer 2 approves, settlement is Armed | 0            | 0          | 0            | 0            | 505,000 USDC |
| Execute   | Secret is revealed on Polygon         | 500,000 USDC | 5,000 USDC | 0            | 0            | 0            |

## Step-by-step walkthrough [#step-by-step-walkthrough]

<Steps>
  <Step>
    ### Builder generates the raw secret [#builder-generates-the-raw-secret]

    Builder opens the settlement wizard and generates a raw secret. The wizard supports either entering the raw secret or entering an existing hashlock, depending on which party creates the settlement.

    * Raw secret: `closing-secret-apt-101-2025`
    * Hashlock: `0x920eda3b2f7ffb9adef73772ed5ef26ea12e8934c8ae5f2b24ec5a0c07ff8969`

    Builder keeps the raw secret private and shares only the hashlock with the Buyers before approval.
  </Step>

  <Step>
    ### Builder creates the Ethereum settlement [#builder-creates-the-ethereum-settlement]

    Builder configures the Ethereum settlement:

    1. Adds two local flows for the APT-101 transfers to Buyer 1 and Buyer 2.
    2. Adds the four Polygon USDC flows as external flows.
    3. Enters the shared hashlock.
    4. Sets the timelock to January 20, 2025 at 17:00 UTC.
    5. Enables auto-execute for this walkthrough.
    6. Submits the transaction.

    The Ethereum settlement now describes both sides of the deal, but it can execute only the Ethereum APT-101 flows.
  </Step>

  <Step>
    ### Buyers verify the Ethereum settlement [#buyers-verify-the-ethereum-settlement]

    Buyer 1 and Buyer 2 check the Ethereum settlement before they create and approve the Polygon side:

    * The local flows send 50 APT-101 to each Buyer.
    * The external flows match the Polygon USDC obligations.
    * The hashlock matches the value they use on Polygon.
    * The Ethereum timelock gives them enough time to reveal the secret after it becomes public on Polygon.

    Builder does not share the raw secret at this stage.
  </Step>

  <Step>
    ### Buyer 1 creates the Polygon settlement [#buyer-1-creates-the-polygon-settlement]

    Buyer 1 creates the matching Polygon settlement:

    1. Adds four local flows for the USDC payments to Builder and Notary.
    2. Adds the two Ethereum APT-101 flows as external flows.
    3. Enters the same hashlock used on Ethereum.
    4. Sets the timelock to January 19, 2025 at 17:00 UTC.
    5. Enables auto-execute for this walkthrough.
    6. Submits the transaction.

    The Polygon settlement can execute only the Polygon USDC flows.
  </Step>

  <Step>
    ### Builder approves on Ethereum [#builder-approves-on-ethereum]

    Builder approves the Ethereum settlement:

    1. Opens the Ethereum settlement detail page.
    2. Selects **Approve**.
    3. Confirms the transaction that transfers 100 APT-101 into the XvP contract.

    The Ethereum settlement enters **Armed** state because its only local sender has approved.
  </Step>

  <Step>
    ### Buyers approve on Polygon [#buyers-approve-on-polygon]

    Buyer 1 approves first:

    1. Opens the Polygon settlement.
    2. Selects **Approve**.
    3. Confirms the transaction that transfers 252,500 USDC into the XvP contract.

    The settlement remains pending until Buyer 2 also approves.

    Buyer 2 then approves:

    1. Opens the Polygon settlement.
    2. Selects **Approve**.
    3. Confirms the transaction that transfers 252,500 USDC into the XvP contract.

    The Polygon settlement enters **Armed** state.
  </Step>

  <Step>
    ### Builder reveals the secret on Polygon [#builder-reveals-the-secret-on-polygon]

    Builder reveals the raw secret on the Polygon settlement to claim the USDC:

    1. Opens the Polygon settlement.
    2. Selects **Reveal Secret**.
    3. Enters `closing-secret-apt-101-2025`.
    4. Confirms the transaction.

    Because auto-execute is enabled in this walkthrough, revealing the valid secret executes the local Polygon flows:

    * Builder receives 500,000 USDC.
    * Notary receives 5,000 USDC.

    The Polygon settlement is **Executed**. The raw secret is now public on-chain.
  </Step>

  <Step>
    ### Buyers reveal the same secret on Ethereum [#buyers-reveal-the-same-secret-on-ethereum]

    After the Polygon reveal, Buyer 1 or Buyer 2 can reuse the public raw secret on the Ethereum settlement:

    1. Opens the Ethereum settlement.
    2. Selects **Reveal Secret**.
    3. Enters `closing-secret-apt-101-2025`.
    4. Confirms the transaction.

    Because auto-execute is enabled in this walkthrough, revealing the valid secret executes the local Ethereum flows:

    * Buyer 1 receives 50 APT-101.
    * Buyer 2 receives 50 APT-101.

    The Ethereum settlement is **Executed**.
  </Step>
</Steps>

## What can go wrong [#what-can-go-wrong]

| Scenario                                                         | What happens                                                                                                                                         | What to do                                                                                                              |
| ---------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| Secret is never revealed before January 19                       | The Polygon settlement expires. Buyers can withdraw their USDC from the Polygon settlement.                                                          | Do not reveal on Ethereum. Let both sides expire or withdraw according to each settlement's local state.                |
| Secret is revealed on Polygon but not Ethereum before January 20 | The Polygon USDC flows execute. The Ethereum settlement remains available until its timelock. After expiry, Builder can withdraw the APT-101 tokens. | Buyers should reveal on Ethereum as soon as the Polygon reveal transaction is final enough for their operating process. |
| Buyer 2 does not approve on Polygon                              | The Polygon settlement does not reach Armed state. Execution stays blocked until all local senders approve.                                          | Wait for approval or let the settlement expire, then withdraw local assets from that settlement.                        |
| Ethereum is congested after the Polygon reveal                   | Buyers may run out of time before the Ethereum timelock.                                                                                             | Use staggered timelocks and reveal with enough operational margin for finality and retries.                             |

## Next steps [#next-steps]

<Cards>
  <Card title="Create a settlement" href="/docs/operators/user-guides/system-addons/xvp-settlement/actions/create">
    Configure local and external flows in the settlement wizard.
  </Card>

  <Card title="Reveal secret" href="/docs/operators/user-guides/system-addons/xvp-settlement/actions/reveal-secret">
    Reveal a raw HTLC secret on an armed settlement.
  </Card>

  <Card title="Withdraw expired" href="/docs/operators/user-guides/system-addons/xvp-settlement/actions/withdraw-expired">
    Recover local assets from an expired settlement.
  </Card>
</Cards>
