Quickstart
In about ten minutes: a customer, test funds, a guaranteed rate for 3 USDC, a lock, settlement, and the lock.settled event. Everything runs in the sandbox on Arc testnet with test tokens.
1. Get a key
Get a sandbox key, then set two variables:
export CERTA_API_URL=https://sandbox-api.13-140-25-211.sslip.io
export CERTA_API_KEY=sk_test_…2. Run the whole flow
Each sample does the same steps. The sandbox holds a test wallet for the customer (managed execution), so you sign nothing. Time travel moves the lock to maturity, so you do not wait an hour.
#!/bin/sh
# Quickstart: from a sandbox key to a settled lock, with curl and jq.
# Run: CERTA_API_URL=https://… CERTA_API_KEY=sk_test_… sh quickstart.sh
set -eu
API="$CERTA_API_URL"
KEY="$CERTA_API_KEY"
post() { # post PATH JSON
curl -sS --fail-with-body -X POST "$API$1" \
-H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" -d "$2"
}
get() { curl -sS --fail-with-body "$API$1" -H "Authorization: Bearer $KEY"; }
wait_until() { # wait_until PATH JQ_TEST
i=0
until [ "$(get "$1" | jq -r "$2")" = true ]; do
i=$((i + 1)); [ "$i" -lt 60 ] || { echo "timed out on $1" >&2; exit 1; }; sleep 2
done
}
# 1. A customer, with a test wallet Certa holds for them (sandbox only).
CUSTOMER=$(post /v1/customers '{"name":"Acme GmbH","country":"DE","managedWallet":true}' | jq -r .id)
post "/v1/customers/$CUSTOMER/kyb" '{"company":"Acme GmbH","country":"DE"}' >/dev/null
wait_until "/v1/customers/$CUSTOMER" '.kybStatus == "approved"'
# 2. Test USDC for the wallet, once a day. The grant depends on the deployment:
# 5 USDC in the hosted sandbox.
post /v1/sandbox/faucet "{\"customerId\":\"$CUSTOMER\"}" >/dev/null
# 3. A quote: sell 3 USDC for EURC in one hour, at a guaranteed rate.
QUOTE=$(post /v1/quotes "{\"pair\":\"USDC/EURC\",\"side\":\"sell_base\",\"usdcNotional\":\"3000000\",\"tenorSeconds\":3600,\"customerId\":\"$CUSTOMER\"}")
echo "$QUOTE" | jq '{rate, receiveAmount, fee}'
# 4. Lock it. "managed" signs with the customer's sandbox wallet.
LOCK=$(post /v1/locks "{\"quoteId\":\"$(echo "$QUOTE" | jq -r .id)\",\"execution\":\"managed\"}" | jq -r .id)
wait_until "/v1/locks/$LOCK" '.status == "active"'
# 5. Skip the hour: time travel to maturity, then settle.
post "/v1/sandbox/locks/$LOCK/advance" '{"to":"maturity"}' >/dev/null
post "/v1/locks/$LOCK/settle" '{"execution":"managed"}' >/dev/null
# 6. Listen for lock.settled (here by polling events; see "Handle webhooks safely").
wait_until "/v1/events?type=lock.settled&limit=100" "[.data[].data.id] | index(\"$LOCK\") != null"
echo "Settled: lock $LOCK"
// Quickstart: from a sandbox key to a settled lock.
// Save as quickstart.mts (it uses top-level await), then run:
// CERTA_API_URL=https://… CERTA_API_KEY=sk_test_… npx tsx quickstart.mts
import { Certa } from "@certa-fx/sdk";
const certa = new Certa({
apiKey: process.env.CERTA_API_KEY!,
baseUrl: process.env.CERTA_API_URL!,
});
// 1. A customer, with a test wallet Certa holds for them (sandbox only).
const customer = await certa.customers.create({
name: "Acme GmbH",
country: "DE",
managedWallet: true,
});
await certa.customers.startKyb(customer.id, { company: "Acme GmbH", country: "DE" });
await certa.customers.waitForKyb(customer.id); // about 5 seconds in the sandbox
// 2. Test USDC for the wallet, once a day. The grant depends on the deployment:
// 5 USDC in the hosted sandbox.
await certa.sandbox.faucet({ customerId: customer.id });
// 3. A quote: sell 3 USDC for EURC in one hour, at a guaranteed rate.
const quote = await certa.quotes.create({
pair: "USDC/EURC",
side: "sell_base",
usdcNotional: "3000000", // 3 USDC, in minor units (6 decimals)
tenorSeconds: 3600,
customerId: customer.id,
});
console.log(`Rate ${quote.rate}: ${quote.receiveAmount} EURC minor units, fee ${quote.fee}`);
// 4. Lock it. "managed" signs with the customer's sandbox wallet.
const lock = await certa.locks.create({ quoteId: quote.id, execution: "managed" });
await certa.locks.waitFor(lock.id, ["active"]);
// 5. Skip the hour: time travel to maturity, then settle.
await certa.sandbox.advance(lock.id, "maturity");
await certa.locks.settle(lock.id, { execution: "managed" });
// 6. Listen for lock.settled (here by polling events; see "Handle webhooks safely").
const settled = await certa.events.waitFor(
"lock.settled",
(e) => (e.data as { id: string }).id === lock.id,
);
console.log(`Settled: ${settled.type} for lock ${lock.id}`);
"""Quickstart: from a sandbox key to a settled lock.
Run: CERTA_API_URL=https://... CERTA_API_KEY=sk_test_... python quickstart.py
"""
import os
from certa import Certa
with Certa(os.environ["CERTA_API_KEY"], base_url=os.environ["CERTA_API_URL"]) as certa:
# 1. A customer, with a test wallet Certa holds for them (sandbox only).
customer = certa.customers.create(name="Acme GmbH", country="DE", managedWallet=True)
certa.customers.start_kyb(customer["id"], company="Acme GmbH", country="DE")
certa.customers.wait_for_kyb(customer["id"]) # about 5 seconds in the sandbox
# 2. Test USDC for the wallet, once a day. The grant depends on the deployment:
# 5 USDC in the hosted sandbox.
certa.sandbox.faucet(customer["id"])
# 3. A quote: sell 3 USDC for EURC in one hour, at a guaranteed rate.
quote = certa.quotes.create(
pair="USDC/EURC",
side="sell_base",
usdcNotional="3000000", # 3 USDC, in minor units (6 decimals)
tenorSeconds=3600,
customerId=customer["id"],
)
print(f"Rate {quote['rate']}: {quote['receiveAmount']} EURC minor units, fee {quote['fee']}")
# 4. Lock it. "managed" signs with the customer's sandbox wallet.
lock = certa.locks.create(quote["id"], execution="managed")
certa.locks.wait_for(lock["id"], ("active",))
# 5. Skip the hour: time travel to maturity, then settle.
certa.sandbox.advance(lock["id"], "maturity")
certa.locks.settle(lock["id"], execution="managed")
# 6. Listen for lock.settled (here by polling events; see "Handle webhooks safely").
settled = certa.events.wait_for("lock.settled", lambda e: e["data"]["id"] == lock["id"])
print(f"Settled: {settled['type']} for lock {lock['id']}")
Install
- TypeScript:
npm install @certa-fx/sdk, save the sample asquickstart.mts(the.mtsextension runs it as an ES module, which top-levelawaitneeds), thennpx tsx quickstart.mts - Python:
pip install certa, thenpython quickstart.py - curl: needs
curlandjq; runsh quickstart.sh
The faucet funds each organisation once per 24 hours. A second run with the same key stops at the faucet with 429 RATE_LIMITED: get a new sandbox key, or change the sample to reuse the customer the first run funded.
What happened
- The customer passed sandbox KYB, which approves in about 5 seconds.
- The faucet sent test USDC to the customer's wallet (5 USDC in the hosted sandbox).
- The quote fixed the EURC the customer will receive. It is firm for 30 seconds; the lock made from it holds that amount until maturity.
- Creating the lock took a 5% deposit and the fee. With managed execution the lock is
activeas soon as its transaction is confirmed on Arc (itsconfirmedAt, a second or two); time travel and settle may take a few seconds more while the sandbox indexes it. - Settlement took the 3 USDC, paid the EURC, and returned the deposit. If the sandbox's Settlement is ever short of EURC, the lock still settles and the EURC is owed to the wallet: the sandbox claims it for Certa-held wallets within a few minutes, and your own wallet claims it with
Settlement.claim(token). - The sample waited for
lock.settledby pollingGET /v1/events. In production you receive it by webhook: see Handle webhooks safely.
Next
- Concepts: deposits, tenors, cancellations, defaults.
- Lock the rate for an invoice with the customer's own wallet.