- REST API for product metadata, APY history, fee stats, user position, vault health
- Standard ERC-4626 contract (
BarkerEngine) for deposit / withdraw — call it directly from your frontend with any wallet library - Webhooks for APY changes, TVL alerts, vault pauses
End-to-end flow
1. List products and pick one
2. Connect the user’s wallet
Use whatever you already have — Wagmi / RainbowKit / Privy / your own connector. Barker doesn’t care. The only requirement: by the time the user clicks “Deposit”, their wallet is connected to the samechain_id as the product (e.g. Base = 8453).
3. Deposit
BarkerEngine is a standard ERC-4626 vault. Two transactions: approve the underlying token, then deposit.
Tip — single-transaction UX: the underlying USDC contract on most chains supports EIP-2612permit. If you collect apermitsignature off-chain you can replace theapprovetx with a no-cost signature, then bundlepermit + depositin a single transaction. See Smart Contracts → permit flow.
4. Show the user’s position
engine.balanceOf(user) directly from the chain — the API serves the same value but with ~30s edge cache.
5. Withdraw / redeem
Two ERC-4626 entrypoints:engine.redeem(shares, receiver, owner)— burn N shares, receive whatever assets they’re worthengine.withdraw(assets, receiver, owner)— receive exactly N assets, burn whatever shares are required
viaengine.previewWithdraw(assets)`.
viem
redeem is one transaction — no approve needed (engine shares are owned by the user already).
6. Listen for on-chain events (optional)
If you want server-side reconciliation rather than polling, subscribe to engine events:| Event | When | Useful for |
|---|---|---|
Deposit(sender, owner, assets, shares) | User deposits | Confirm deposit landed, update internal ledger |
Withdraw(sender, receiver, owner, assets, shares) | User redeems | Confirm withdrawal landed |
FeeAccrued(barkerFeeShares, partnerFeeShares, totalAssets, ...) | Yield is split | Reconcile partner fee earnings |
7. Subscribe to webhooks (optional)
For events Barker pushes — lifecycle (deposit.confirmed, redeem.confirmed, redeem.requested) and operational (apy_change, tvl_alert, vault_pause) — see Webhooks and Deposit/Redeem Lifecycle. Not strictly required for a working UI (you can watch chain logs from the client — see the reference implementation below), but strongly recommended for backend reconciliation: DB writes, accounting, ops alerts.
Reference implementation — Next.js + wagmi
The snippets above show each step in isolation. Here’s the same flow as a single Next.js 16 App Router page that you can copy and adapt — three files, runnable end to end. Architecture in one sentence: server component fetches product metadata with the API key (which never leaves the server); client component drives wallet + writes + uses wagmi’suseWatchContractEvent for instant UI updates; a separate Route Handler receives Barker webhooks for backend reconciliation (DB, accounting). The two channels are independent — your UI doesn’t block on webhook delivery, and your backend doesn’t depend on the user keeping the tab open.
| Channel | Lives in | Triggers | Purpose |
|---|---|---|---|
useWatchContractEvent | Browser | Engine Deposit / Withdraw log seen by user’s RPC | Instant UI refresh while the user is on the page |
| Webhook Route Handler | Your backend | Barker watcher confirms log at depth, signs + delivers | Durable backend state — DB writes, accounting, ops alerts |
- Wagmi config +
<WagmiProvider>setup — see wagmi.sh/react/getting-started - Permit-based single-tx UX — see Smart Contracts → permit
- Engine ABI import — see Smart Contracts → minimal ABI
- Async-vault
redeem.requestedhandling — see Lifecycle → async vault sequence - Failure handling (RPC outage, tx revert, replacement) — see Failure modes
Sandbox checklist
Before you commit production engineering time, verify the headless flow against sandbox:-
bk_test_*key issued (Portal → API Keys) - Sandbox product slug visible in
GET /api/partner/products - Sandbox USDC obtained from the Sandbox page → Mint Test USDC
-
approve + depositround-trips on testnet, position endpoint reflects new balance within 30s -
redeemround-trips, position drops to 0 - Same code path works against
bk_live_*key (only the key changes, base URL is identical)
Production checklist
- Production engine deployed (status
activein Portal → Products) - Frontend reads
chain_idfrom the product response and switches chain before signing - Error states surfaced: vault paused (poll
/health), insufficient allowance, user rejected signature, network mismatch - Slippage guard / minimum shares check on
deposit(previewDepositmatches your displayed APY ± a tolerance) - Compliance disclosures shown to user before deposit
What’s next
- Smart Contracts reference — ABI, deployed addresses, event signatures
- Multi-tier products — offer 3 risk profiles
- Errors — error code catalog
- Webhooks — push events from Barker → you