JavaScript/TypeScript SDK (Web & Telegram Mini Apps)
The official @localcredit/sdk-js package makes integrating Localcredit into web apps or Telegram Mini Apps fast and secure. It handles authentication, proof signing, API calls, billing, and seamless redirects automatically.Installationbash
npm install @localcredit/sdk-js
# or
yarn add @localcredit/sdk-jsSetuptypescript
import { Localcredit } from '@localcredit/sdk-js';
// Initialize with your API key (from developer dashboard)
const lc = new Localcredit({
apiKey: 'your_api_key_here',
environment: 'production' // or 'test' for sandbox
});1. Fetch User Scoretypescript
// Get the user's signed proof (wallet signature)
const userProof = await lc.requestProof();
// This opens a wallet modal (TON Connect for Mini Apps, WalletConnect for web)
// Query the score
try {
const result = await lc.getScore(userProof);
console.log('Score:', result.score); // 82
console.log('Risk Tier:', result.riskTier); // 'Low'
console.log('Estimated Limit:', result.creditLimitUsd); // 5200
console.log('Breakdown:', result.breakdown);
} catch (error) {
if (error.code === 'NO_SCORE') {
// User has no Localcredit profile yet
await lc.redirectToOnboarding(); // seamless deep link
}
}2. Handle New Users (Redirect & Return)typescript
3. Report Loan Outcometypescript
4. Manage Subscriptiontypescript
5. TON-Specific Features (Telegram Mini Apps)The SDK automatically detects TON environment and uses TON Connect.typescript
Error Handlingtypescript
Full TypeScript SupportAll methods are fully typed:typescript
The SDK abstracts away authentication, signatures, billing, and cross-environment differences so you can focus on building great user experiences.
Most integrations go live in under an hour.
Last updated