Embed the modal
Configure the SDK once, then open it with a standard action.
On this page
Install the SDK
npm install @termbook/sdk viemThe published SDK supplies the borrower modal, wallet adapters and account management. Your app connects to the Termbook API.
Choose an approved integration
An active app token selects the reviewed integration version. The SDK resolves its chain, RPC and contract addresses through https://api.termbook.xyz. The token is a public integration identifier; the borrower still authorizes transactions.
NEXT_PUBLIC_TERMBOOK_APP_TOKEN=your_active_app_tokenTo use a local Termbook API, pass apiBase: "http://127.0.0.1:3002" when creating the client.
Connect an EVM wallet
Termbook supplies evm_wallet, an adapter for a connected viem WalletClient. Your app’s wallet provider connects the borrower’s Monad wallet. The adapter forwards signing and transactions to that wallet; it does not create a key or hold funds.
import { evm_wallet } from "@termbook/sdk";
const wallet = await evm_wallet(wallet_client);wallet_client is the connected WalletClient from your app’s wallet provider. If your app does not have one, this browser example connects an injected wallet on Monad testnet. Call it from a user click handler, then pass its result to open_credit in the next section.
import { createWalletClient, custom, type EIP1193Provider } from "viem";
import { monadTestnet } from "viem/chains";
export async function connect_wallet() {
const provider = (window as Window & {
ethereum?: EIP1193Provider;
}).ethereum;
if (!provider) throw new Error("Install an EVM wallet to continue.");
const client = createWalletClient({
chain: monadTestnet,
transport: custom(provider),
});
await client.requestAddresses();
await client.switchChain({ id: monadTestnet.id });
return client;
}| Wallet | Connection & purpose |
|---|---|
| Monad borrower wallet | Connected by your app; signs House terms and account actions through evm_wallet. |
| Collateral wallet | Connected by the modal; locks and receives collateral on its source chain. SOL requires a Solana wallet. |
| Credit Account | Created by the protocol; holds borrowed funds and app assets. It is not a browser wallet. |
Open Termbook
import { create_termbook, evm_wallet } from "@termbook/sdk";
import type { WalletClient } from "viem";
export async function open_credit(wallet_client: WalletClient) {
const termbook = create_termbook({
app_token: process.env.NEXT_PUBLIC_TERMBOOK_APP_TOKEN!,
wallet: await evm_wallet(wallet_client),
});
const modal = termbook.open({
action: {
use_case: "spot",
capability: "place_order",
params: {
market_id: "0x1f57a841540fe23c2989387c18f2cb1335cbae92",
direction: "buy",
order_type: "market",
amount: { spend: 10_000n },
slippage_bps: 50,
},
},
});
await modal.ready;
return modal;
}Call open_credit with the connected client. With the optional connection example, call open_credit(await connect_wallet()). Reuse the configured Termbook client for subsequent opens while the connected account is unchanged; recreate it when the borrower account changes.
open returns a TermbookModal with a ready promise. The modal owns offer review, source-wallet connection, collateral setup, execution and account management. The action must belong to the active integration version.