SDK, HTTP API and AgentKit
Build your own agent or app on Based Loans with the TypeScript SDK, the HTTP API or Coinbase AgentKit.
Everything the MCP server can do is also available as a TypeScript SDK, a plain HTTP API, and a Coinbase AgentKit plugin. All three read live from Base and never hold keys.
TypeScript SDK
npm install @basedloans/sdk viem
import { createBasedLoans } from "@basedloans/sdk"
const bl = createBasedLoans({ rpcUrl: process.env.BASE_RPC_URL })
const WETH = "0x4200000000000000000000000000000000000006"
const quote = await bl.quoteBorrow({ asset: WETH, collateralAmount: "0.5", term: "short" })
const plan = await bl.buildBorrow({ asset: quote.asset, collateralAmount: "0.5", term: "short", borrower: "0xYourWallet" })
// plan.steps: send each one in order with your wallet
Main methods:
- Read:
getProtocolParams,listMarkets,getMarket,getRiskReport,quoteBorrow,getLoan,getBorrowerLoans,getLenderPosition,requestTokenListing - Prepare:
buildBorrow,buildBuyback,buildDeposit,buildSetLimits,buildWithdraw,buildClaimProceeds,buildClaimCollateral,buildSetAutoRedeploy - Check:
simulatedry-runs a prepared step and explains a failure in plain words
Full reference: @basedloans/sdk on npm.
HTTP API
For agents that cannot use MCP. All endpoints are GET and return JSON. https://mcp.based.loans/v1 lists every endpoint.
| Endpoint | Returns |
|---|---|
/v1/protocol | Fees, terms and minimums |
/v1/markets | Accepted tokens (?only_with_funds=true for tokens with USDC available) |
/v1/risk?asset= | Risk report for a token |
/v1/quote?asset=&collateral=&term= | Loan quote |
/v1/loans?borrower= | A wallet's loans |
/v1/lender?address= | A lender's position |
/v1/tx/borrow?asset=&collateral=&term=&borrower= | Transactions to open a loan |
/v1/tx/buyback?loan_id=&borrower= | Transactions to buy back |
/v1/tx/deposit?amount_usdc=&lender=&limits=WETH:500 | Transactions to deposit and set limits |
Transaction endpoints return a calls list in the format Base wallets use for send_calls, with approvals first when needed.
Coinbase AgentKit
npm install @basedloans/agentkit @coinbase/agentkit
import { AgentKit } from "@coinbase/agentkit"
import { basedLoansActionProvider } from "@basedloans/agentkit"
const agentKit = await AgentKit.from({
walletProvider, // your agent's wallet on Base
actionProviders: [basedLoansActionProvider()],
})
The provider adds actions such as quote_borrow, borrow, buyback, lend, withdraw and get_risk_report. Transactions are signed by the agent's own wallet.
Agent skill
A ready-made skill file teaches agents the borrowing and lending workflows: always show the buyback cost and due date before borrowing, check risk before lending, and never claim a token request was submitted. It is at skills/based-loans/SKILL.md.