Skip to main content
This guide walks through building the bilateral instruction flow - where a seller submits their side of a trade, shares a trade reference with the buyer, and the buyer submits a matching instruction to create a settlement.

Prerequisites

  • @keystoneos/react installed
  • KeystoneProvider configured with a session token that has instructions:write and templates:read scopes
  • A React project with TypeScript

How bilateral settlement works

In a bilateral flow, two independent parties agree on a trade off-platform (via phone, email, or OMS). Each party submits their side of the trade to KeyStone. When both sides match, a settlement is created automatically. The key points:
  • The first party to submit gets status: "pending_match" and a trade reference
  • The second party submits with that trade reference and gets status: "matched" plus a settlement ID
  • Either party can be the first to submit - there is no required order

Understanding legs

A DvP (Delivery vs Payment) settlement involves two legs: Each party submits both legs in their instruction. The direction is derived automatically from the role:
Each leg specifies its own chain_id and instrument_id (the token contract address).

Building the instruction form

Template selector

Start by letting the user pick a settlement template. Templates define the structure of the settlement (roles, leg types, state machine).

Trade reference input

When matching an existing instruction, the user provides the trade reference they received from the counterparty.

The complete instruction form

This form collects role, party details, template-driven legs, and optional trade reference. Each template defines which leg types are required - for DvP, that is asset_delivery and payment.

Handling results

Pending match - share the trade reference

When the submission returns pending_match, the counterparty has not submitted yet. Show the trade reference prominently so the user can share it.

Matched - navigate to settlement

When the submission returns matched, both sides are in. Navigate directly to the settlement detail page.

Realistic example flow

Here is how a real trade looks end-to-end: 1. Seller at Securitize submits both legs:
2. Seller shares KS-abc12345 with buyer via email or OMS. 3. Buyer at Ondo Capital submits with the trade reference:
4. Settlement is created automatically. The match response carries the new settlement_id; the settlement starts at INSTRUCTED and the engine begins compliance checks. The first webhook both platforms receive is settlement.state.awaiting_deposits once compliance clears (or settlement.state.compliance_checking if a party is flagged).

Error handling

Next steps

Settlement Dashboard

Build a dashboard to monitor all your settlements.

Real-time Tracking

Track settlement progress with live updates after matching.

useSubmitInstruction Reference

Full API reference for the useSubmitInstruction hook.

Bilateral Instructions Guide

Server-side guide for bilateral instruction flow using the SDK.