The Kohin JS is a comprehensive developer toolkit designed to integrate Kohin's decentralized insurance system seamlessly into your applications. It enables efficient interaction with Kohin smart contracts and backend APIs, facilitating management and analytics for user bets, coverage, and liquidity pools.
npm install kohin-js
- Access Key and Secret Key
- Affiliate Address
- Polygon Network RPC URL (Optional)
- Test: Polygon Amoy (Chain ID: 80002)
- Pre-Production: Polygon (Chain ID: 137)
- Production: Polygon Mainnet
import { Kohin } from "kohin-js";
// Initialize Kohin with your access credentials, RPC URL, and affiliate address
const kohin = new Kohin({
accessKey: "your-access-key", // Replace with your unique access key
secretKey: "your-secret-key", // Replace with your secret authentication key
envMode: "test", // Options: 'test', 'preProd', 'prod' (set according to environment)
affiliateAddress: "your-affiliate-address", // Replace with your affiliate address
rpcUrl: "https://your-rpc-url.com", // (Optional) Replace with your blockchain RPC URL
});
// Get Active Bets
const activeBets = await kohin.getActiveBetData({
bettorAddress: "0x...",
pageCount: 1,
});
// Get Bet Details
const details = await kohin.getBetDetails({
betId: "0x...",
});
// Get Odds History
const history = await kohin.getOddsHistory({
conditionId: "0x...",
});
// Calculate Premium
const premium = await kohin.calculatePremium({
betId: 123,
betType: "Combo", // For an "Express" bet, pass betType as "Combo" and for an "Ordinar" bet, pass betType as "Single."
odds: 2.5,
betAmount: 100,
numLegs: 2,
});
// Buy Cover
import { useWalletClient } from "wagmi";
const walletClient = useWalletClient();
const approveRes = await kohin.approveAmount({
amount: 1000, // The amount to be approved for processing (e.g., 1000 USDT)
walletClient: walletClient?.data, // The wallet client instance used to authorize the approval request
});
const cover = await kohin.buyCover({
betId: 219, // The ID of the bet to insure
betType: "Combo", // For an "Express" bet, pass betType as "Combo" and for an "Ordinar" bet, pass betType as "Single."
coverPremium: 53982374n, // The premium amount for the insurance cover (bigint format)
slippagePercent: 5, // Slippage percentage (between 1 and 100)
betAmount: 1000, // The total amount placed on the bet
walletClient: walletClient?.data, // The wallet client instance used to process the payment for the insurance cover
});
// Add Liquidity
const walletClient = useWalletClient();
const approveRes = await kohin.approveAmount({
amount: 56.68, // The amount to be approved for processing (e.g., 56.68 USDT)
walletClient: walletClient?.data, // The wallet client instance used to authorize the approval request
});
const deposit = await kohin.addLiquidity({
amount: 1000, // The amount to be added to liquidity (e.g., 1000 USDT)
walletClient: walletClient?.data, // The wallet client instance used to facilitate the liquidity addition
});
// Remove Liquidity
const walletClient = useWalletClient();
const withdrawal = await kohin.removeLiquidity({
depositId: 1099511627894, // The unique identifier of the deposit from which liquidity will be removed
percent: 16, // The percentage of liquidity to remove (value between 0 and 100)
walletClient: walletClient?.data, // The wallet client instance used to process the liquidity removal request
});
All methods return a consistent response format:
interface ResponseData<T> {
success: boolean;
data?: T;
error?: string;
}
try {
const result = await kohin.someOperation(params);
if (result.success) {
// Handle success
} else {
// Handle error
}
} catch (error) {
// Handle unexpected errors
}
- viem: Web3 interactions
- axios: API requests
- typescript: Type definitions
- Store credentials securely
- Validate all transaction parameters
- Maintain sufficient gas for transactions
MIT