SDK Guide
The TownSquare SDK (@townsq/mm-sdk) provides developers with tools to interact seamlessly with the protocol — creating accounts, managing loans, depositing, borrowing, repaying, and withdrawing assets — without directly calling smart contracts.
Installation
npm install @townsq/mm-sdkor
yarn add @townsq/mm-sdkInitialization
Before using the SDK, you need to configure the core instance and signer.
import { TSCore, NetworkType, TS_CHAIN_ID, CHAIN_VIEM } from "@townsq/mm-sdk";
import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
// Select network and chain
const network = NetworkType.TESTNET;
const chain = TS_CHAIN_ID.MONAD_TESTNET;
// Initialize SDK configuration
const tsConfig: TSCoreConfig = { network, provider: { evm: {} } };
TSCore.init(tsConfig);
TSCore.setNetwork(network);
// Create signer (example with private key)
const signer = createWalletClient({
chain: CHAIN_VIEM[chain],
transport: http(),
account: privateKeyToAccount("0x..."), // Replace with private key
});
// Set signer
TSCore.setTSsSigner({ signer, tsChainId: chain });Reading Loan Information
The SDK provides utilities to fetch and compute detailed information about a loan, including collateral value, debt value, and health factors. This is useful for dashboards, liquidation bots, or analytics.
Creating Account
The account will be created on the chain defined during initialization.
Creating a Loan
TownSquare supports three loan types:
General Loan → accepts all supported tokens.
Stable Efficiency Loan → restricted to stablecoin-related assets.
MON Efficiency Loan → supports MON-related assets only.
Deposit
Deposit tokens into a loan.
Borrow
Repay
Withdraw
Last updated