DeFi Integrations
Trading, lending, borrowing, and earn products on Base are built on third-party protocols rather than anything the chain provides. Your app’s job is to prepare and simulate a call, show the user what it will do, and let them sign it from their own wallet. The position lives with the protocol, not with you.
Swaps through an aggregator
Section titled “Swaps through an aggregator”The 0x Swap API searches liquidity across exchanges and market makers and hands back a transaction the wallet can simulate, sign, and submit. The AllowanceHolder flow runs in four steps:
- Ask for an indicative
/pricewhile the user is still editing the trade. - Ask for a firm
/quoteonce they are ready to review and sign. - If the quote reports
issues.allowance, approve the returnedspender— for the sell amount only. - Take a fresh quote, simulate its
transaction, submit, and wait for confirmation.
Requests carry chainId 8453 for Base mainnet and an API key that belongs on your server, never in the client. The quote’s own diagnostics are worth reading before you prompt anyone: liquidityAvailable tells you whether a route exists at all, and issues.balance catches an underfunded taker before the wallet does.
Refreshing the quote after approval is not optional bookkeeping. Prices move between the quote and the signature, and minBuyAmount is what protects the user from the difference. Keep the quote request on your backend, return the reviewed transaction fields to the frontend, and submit from the connected wallet.
Supplying to a money market
Section titled “Supplying to a money market”Lending is a supply call against a market the protocol defines. Your app prepares and simulates it; the user signs. What you owe them is an accurate picture of the terms at signing time.
Borrowing against collateral
Section titled “Borrowing against collateral”Borrowing adds a liquidation surface, which makes the display requirement stricter rather than merely advisable. Show collateral value, outstanding debt, the liquidation parameters, and position health — both as they stand and as they would stand after the action.
Health is not static between render and signature. Collateral prices move, oracles update, and interest accrues, so re-fetch immediately before the user signs rather than trusting a value fetched when the screen was drawn. If an action would leave the position unsafe, say so plainly before it is signed, not after.
Vault-based earn
Section titled “Vault-based earn”An earn product is the one-deposit case: the user deposits once and receives vault shares, and the vault handles allocation across its underlying markets. Morpho’s vaults follow the ERC-4626 shape, so share accounting and redemption previews use the interface you already know.
The abstraction is the selling point and also the thing to be careful about. Because the user sees one balance rather than a set of positions, your interface carries the whole burden of showing current redeemable value and the risk behind it. Shares are not a stable unit of account — quote value by converting through the vault, never by treating one share as one token.