Skip to content
CertadocsGet a sandbox key

Guides

Lock the rate for an invoice

Your customer owes EUR in 30 days and holds USDC. Lock the rate now so the EURC they receive at maturity is fixed. In live mode the customer signs with their own wallet (execution: "unsigned"); the sandbox can also sign for them (managed).

1. Register the customer and their wallet

const customer = await certa.customers.create({
  name: "Acme GmbH",
  country: "DE",
  wallets: ["0xCustomerWallet…"],
});
await certa.customers.startKyb(customer.id, { company: "Acme GmbH", country: "DE" });

Wait for the customer.kyb_updated event (or waitForKyb) before quoting: a quote for a customer without KYB is refused with KYB_REQUIRED.

2. Quote for the invoice date

const quote = await certa.quotes.create({
  pair: "USDC/EURC",
  side: "sell_base",                 // the customer delivers USDC, receives EURC
  usdcNotional: "9500000000",        // 9,500 USDC in minor units
  maturity: "2027-01-04T09:00:00Z",  // the invoice due date
  customerId: customer.id,
});
// Show quote.receiveAmount, quote.fee and quote.deposit to the customer now:
// the quote is firm for 30 seconds.

3. Lock, and have the customer sign

const lock = await certa.locks.create({ quoteId: quote.id, execution: "unsigned" });
for (const tx of lock.transactions) {
  // Send each with the customer's wallet, in order: approve, then createLock.
  await wallet.sendTransaction({ to: tx.to, data: tx.data, value: BigInt(tx.value) });
}
const active = await certa.locks.waitFor(lock.id, ["active", "expired"]);

The transactions must land before the quote expires; if they do not, the lock ends as expired and nothing is taken.

4. Settle at maturity

From maturity, settle with POST /v1/locks/{id}/settle: it returns the transactions that approve and deliver the USDC. Once the delivery is approved, the keeper settles the lock if you do not. Listen for lock.maturing to remind the customer, and lock.settled to mark the invoice paid. Without delivery 48 hours after maturity, the lock defaults (see Defaults).