← Contract Hero · WorkLearnPlugins
acc-deepbook-course
All lessons Lesson 2 · DeepBook track

Swap over the CLOB

Swap wallet coins straight over a DeepBook order book with swapExactQuoteForBase. No BalanceManager: coins go in, coins come out in a single transaction, protected by a real on-chain slippage guard.

swapExactQuoteForBase transferObjects signAndExecute normalizeStructTag
What you'll learn

The lightest possible trade

  • ›The simplest DeepBook trade: wallet coins through the pool, no account object in the middle.
  • ›The [base, quote, deep] leftover-coin tuple the builder returns, which you must transfer back or the transaction aborts.
  • ›minOut as an on-chain slippage guard, and reading the real fill from the transaction's balanceChanges.
Walkthrough

Five sections, end to end

  1. Connect

    Load the deployment manifest and construct a SuiGrpcClient extended with the DeepBook SDK.

    src/sandbox.ts
  2. Fund & execute

    Mint and faucet-fund a fresh keypair, then send transactions that return balanceChanges so you can read results.

    src/sandbox.ts
  3. Swap

    Call swapExactQuoteForBase and transfer the [base, quote, deep] coins back to the sender, or the whole transaction aborts.

    src/swap.ts
  4. Read the fill

    Sum the positive delta of the base coin credited to you to report the genuine amount filled, not an estimate.

    src/swap.ts
  5. Drive it

    Wire the smoke UI and prove minOut reverts on chain with MoveAbort code 12 when slippage is unsatisfiable.

    src/App.tsx · src/main.tsx
Run it

Start this lesson

claude code
/acc-deepbook-course:start
# then pick "Swap over the CLOB"

Already installed? Run the start command and choose this lesson from the catalog.

New here? Follow the install steps first. The course brings up a local sandbox and gates each section with pnpm vitest run.