This guide walks you through a complete DvP (Delivery vs. Payment) settlement using bilateral instruction submission and autonomous on-chain execution.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.
Prerequisites
- A KeyStone OS platform account with API credentials (M2M client ID and secret) - find these in the KeyStone Dashboard under Settings > General
- An active environment (sandbox or production)
Step 1: Authenticate
KeyStone uses Auth0 M2M (client credentials) tokens for platform API access.access_token is a JWT valid for 24 hours. Include it in all API requests:
Step 2: Browse available templates
Templates define the settlement workflow and are pre-configured by KeyStone. Browse the available templates to find the right one for your use case.dvp-standard template. Note the slug field - you will reference it when submitting instructions.
Step 3: Submit the seller instruction
Submit one side of the trade. KeyStone generates a trade reference that your counterparty will use to submit the other side.Step 4: Share trade reference with counterparty
Send thetrade_reference to your counterparty through your own channels (email, chat, API integration, etc.). They will use it to submit the matching instruction.
Step 5: Counterparty submits matching instruction
The counterparty submits their side with the same trade reference:Step 6: Settlement created on-chain
After matching, KeyStone creates the settlement on the SettlementCoordinator contract. The state machine rules are stored on-chain, and the settlement entersINSTRUCTED.
Step 7: Compliance runs automatically
If the template has compliance configured, KeyStone screens all parties through LSEG World-Check (entity) and CipherOwl (wallet), then attests the results to the ComplianceRegistry on-chain. The contract enforces that compliance must pass before the settlement can advance.Step 8: Both parties deposit to escrow
When the settlement reachesAWAITING_DEPOSITS, the settlement response includes a deposit_secret and deposit_key for each leg. Both parties deposit their assets directly to the escrow smart contract by calling depositLeg(settlementId, legIndex, depositSecret). Your platform uses its custody provider to sign the deposit transaction. KeyStone is not involved in the deposit step.
Step 9: Contracts auto-execute and finalize
The escrow contract detects when all deposits are complete and notifies the SettlementCoordinator. The coordinator verifies the atomicity gate (all legs deposited) and callsexecuteSettlement(settlementId, recipients[]) on the escrow - revealing recipient addresses only at this point. Tokens go to the buyer, USDC goes to the seller. The settlement transitions to FINALIZED.
Step 10: Check the result
What happened
| Phase | Who drives it |
|---|---|
| Instruction matching | KeyStone API (off-chain) |
| On-chain creation | KeyStone engine |
| Compliance screening | KeyStone compliance oracle |
| Compliance attestation | KeyStone compliance oracle |
| Past compliance gate | KeyStone engine (one transition) |
| Deposits | Parties deposit directly to escrow |
| Execution | Contracts (autonomous) |
| Finalization | Contracts (autonomous) |
| Timeout (if needed) | Anyone (permissionless) |
Next: Authentication
Learn about M2M tokens, user tokens, scopes, and environment resolution.