npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

kton-sdk

v1.1.2

Published

Advanced staking SDK for TON blockchain with KTON token support

Downloads

6

Readme

🚀 KTON SDK


📖 Overview

KTON SDK is a comprehensive TypeScript/JavaScript library for seamless integration with TON blockchain's liquid staking ecosystem. Now supporting both KTON and pKTON protocols with a unified API interface, making it easy to build applications that work with multiple staking protocols.

🆕 What's New in v1.1.0

  • 🔄 Dual Protocol Support: Full KTON and pKTON compatibility
  • 🔀 Dynamic Token Switching: Switch between protocols at runtime
  • 🔙 100% Backward Compatible: Existing code works unchanged
  • 🎯 Unified API: Same interface for both token types

✨ Key Features

  • 🔄 Dual Protocol Support - KTON and pKTON liquid staking protocols
  • 📊 Real-time Analytics - APY, TVL, and detailed staking metrics
  • 💰 Multi-Strategy Support - Standard, instant, and best-rate unstaking
  • 🔀 Dynamic Token Switching - Switch between KTON/pKTON at runtime
  • 🔗 Wallet Integration - Seamless TonConnect integration
  • 📱 Cross-platform - Browser, Node.js, and mobile environments
  • 🏗️ TypeScript First - Full type safety and IntelliSense support
  • Performance Optimized - Built-in caching and efficient API usage

🚀 Quick Start

Installation

# Using npm
npm install kton-sdk

# Using yarn
yarn add kton-sdk

# Using pnpm
pnpm add kton-sdk

Basic Usage

KTON (Default - Backward Compatible)

import { KTON } from "kton-sdk";
import { TonConnectUI } from "@tonconnect/ui";

const tonConnectUI = new TonConnectUI({
  manifestUrl: "https://yourapp.com/tonconnect-manifest.json",
});

// Initialize with KTON (default behavior)
const kton = new KTON({
  connector: tonConnectUI,
  isTestnet: false,
});

// All your existing code works unchanged!
await kton.stake(1); // Stake 1 TON
const apy = await kton.getCurrentApy();
const balance = await kton.getStakedBalance();

pKTON Support

// Initialize with pKTON
const pkton = new KTON({
  connector: tonConnectUI,
  tokenType: 'pKTON', // Specify pKTON
  isTestnet: false,
});

// Same API, different protocol
await pkton.stake(1);
const apy = await pkton.getCurrentApy();
const balance = await pkton.getStakedBalance();

Dynamic Token Switching

import { KTON, type TokenType } from "kton-sdk";

const sdk = new KTON({ connector: tonConnectUI });

// Check current token type
console.log(sdk.getTokenType()); // "KTON"

// Switch to pKTON
await sdk.switchTokenType('pKTON');
console.log(sdk.getTokenType()); // "pKTON"

// Listen for switches
sdk.addEventListener("token_type_switched", () => {
  console.log("Now using:", sdk.getTokenType());
});

Browser Integration

<!DOCTYPE html>
<html>
<head>
  <script src="https://unpkg.com/kton-sdk@latest/dist/kton-sdk.min.js"></script>
  <script src="https://unpkg.com/@tonconnect/ui@latest/dist/tonconnect-ui.min.js"></script>
</head>
<body>
  <script>
    const { KTON } = window.KTONSDK;
    
    // KTON usage
    const kton = new KTON({
      connector: new TON_CONNECT_UI.TonConnectUI({
        manifestUrl: "https://yourapp.com/tonconnect-manifest.json"
      })
    });
    
    // pKTON usage
    const pkton = new KTON({
      connector: new TON_CONNECT_UI.TonConnectUI({
        manifestUrl: "https://yourapp.com/tonconnect-manifest.json"
      }),
      tokenType: 'pKTON'
    });
  </script>
</body>
</html>

📚 API Reference

Constructor Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | connector | IWalletConnector | Required | TonConnect UI instance | | tokenType | 'KTON' \| 'pKTON' | 'KTON' | NEW: Token protocol type | | partnerCode | number | 0x0000000074746f6e | Partner identification code | | tonApiKey | string | undefined | TonAPI key for enhanced rate limits | | isTestnet | boolean | false | Enable testnet mode | | cacheFor | number | 30000 | Cache duration in milliseconds |

Core Methods

Staking Operations

// Basic staking (works with both KTON and pKTON)
await sdk.stake(1.5); // Stake 1.5 TON

// Stake maximum available balance
await sdk.stakeMax();

// Unstaking options
await sdk.unstake(1); // Standard unstaking
await sdk.unstakeInstant(1); // Instant unstaking (higher fees)
await sdk.unstakeBestRate(1); // Best rate unstaking

Balance Management

// Get various balances
const tonBalance = await sdk.getBalance(); // TON balance
const stakedBalance = await sdk.getStakedBalance(); // Staked token balance
const availableBalance = await sdk.getAvailableBalance(); // Available for staking

Analytics & Information

// Staking metrics
const currentApy = await sdk.getCurrentApy(); // Current APY
const historicalApy = await sdk.getHistoricalApy(); // APY history
const tvl = await sdk.getTvl(); // Total Value Locked
const holdersCount = await sdk.getHoldersCount(); // Token holders count

// Market data
const rates = await sdk.getRates();
console.log(`1 TON = ${rates.TONUSD} USD`);
console.log(`1 ${sdk.getTokenType()} = ${rates.KTONTON} TON`);

// Validation rounds
const { roundStart, roundEnd } = await sdk.getRoundTimestamps();

// Withdrawal tracking
const activeWithdrawals = await sdk.getActiveWithdrawalNFTs();
const instantLiquidity = await sdk.getInstantLiquidity();

Token Type Management

// Get current token type
const currentType = sdk.getTokenType(); // 'KTON' | 'pKTON'

// Switch token type
await sdk.switchTokenType('pKTON'); // Switch to pKTON
await sdk.switchTokenType('KTON');  // Switch to KTON

Event Handling

// Listen for SDK events
sdk.addEventListener("initialized", () => {
  console.log("SDK ready!");
});

sdk.addEventListener("token_type_switched", () => {
  console.log("Token type changed to:", sdk.getTokenType());
});

sdk.addEventListener("wallet_connected", () => {
  console.log("Wallet connected");
});

sdk.addEventListener("wallet_disconnected", () => {
  console.log("Wallet disconnected");
});

Cache Management

// Clear cached data
await sdk.clearStorageData(); // Clear all cache
await sdk.clearStorageUserData(); // Clear user-specific cache

🔗 Protocol Support

Contract Addresses

| Protocol | Network | Contract Address | |----------|---------|------------------| | KTON | Mainnet | EQA9HwEZD_tONfVz6lJS0PVKR5viEiEGyj9AuQewGQVnXPg0 | | KTON | Testnet | kQD2y9eUotYw7VprrD0UJvAigDVXwgCCLWAl-DjaamCHniVr | | pKTON | Mainnet | EQDsW2P6nuP1zopKoNiCYj2xhqDan0cBuULQ8MH4o7dBt_7a | | pKTON | Testnet | kQD2y9eUotYw7VprrD0UJvAigDVXwgCCLWAl-DjaamCHniVr |

API Endpoints

| Service | Network | Endpoint | |---------|---------|----------| | TonAPI | Mainnet | https://tonapi.io | | TonAPI | Testnet | https://testnet.tonapi.io | | TonCenter V3 | Mainnet | https://toncenter.com/api/v3 | | TonCenter V3 | Testnet | https://testnet.toncenter.com/api/v3 |

🎮 Demo & Examples

Live Demo

Try the interactive demo to see both KTON and pKTON in action:

# Clone the repository
git clone https://github.com/KTON-IO/KTON-SDK.git
cd KTON-SDK

# Install dependencies
npm install

# Build the SDK
npm run build

# Start demo server
npm run docs

Visit http://localhost:8000/demo in your browser.

Demo Features:

  • 🔗 Connect TON wallet (Tonkeeper, MyTonWallet, etc.)
  • 🔀 Switch between KTON and pKTON protocols
  • 💰 View balances and staking statistics
  • 📈 Real-time APY and TVL data
  • 🔄 Stake/unstake operations
  • 📊 Withdrawal tracking

Example Projects

Check out these example implementations:

🔄 Migration Guide

From v1.0.x to v1.1.0

✅ Zero Breaking Changes: Your existing code will continue to work exactly as before.

Existing Code (Still Works)

// This continues to work unchanged
const kton = new KTON({
  connector: tonConnectUI,
  isTestnet: false
});

Adding pKTON Support

// Option 1: Use separate instances
const ktonSDK = new KTON({ connector, tokenType: 'KTON' });
const pKtonSDK = new KTON({ connector, tokenType: 'pKTON' });

// Option 2: Use dynamic switching
const sdk = new KTON({ connector });
await sdk.switchTokenType('pKTON'); // Switch to pKTON
await sdk.switchTokenType('KTON');  // Switch back

TypeScript Support

import { KTON, type TokenType } from "kton-sdk";

const tokenType: TokenType = 'pKTON'; // Type-safe token selection

// Full TypeScript IntelliSense support
const sdk = new KTON({
  connector: tonConnectUI,
  tokenType, // Fully typed
  isTestnet: false
});

🛠️ Development

Prerequisites

  • Node.js 16+
  • npm, yarn, or pnpm
  • A TON wallet for testing

Building from Source

# Clone repository
git clone https://github.com/KTON-IO/KTON-SDK.git
cd KTON-SDK

# Install dependencies
npm install

# Build the SDK
npm run build

# Run in development mode (with watch)
npm run dev

Available Scripts

| Script | Description | |--------|-------------| | npm run build | Build production bundle | | npm run dev | Development mode with file watching | | npm run clean | Clean build artifacts | | npm run typecheck | Run TypeScript type checking | | npm run lint | Lint code with ESLint | | npm run format | Format code with Prettier | | npm run test | Run test suite | | npm run docs | Start documentation server |

🚀 Deployment

Publishing to NPM

# Build and publish
npm run build
npm publish

CDN Usage

<!-- Latest version -->
<script src="https://unpkg.com/kton-sdk@latest/dist/kton-sdk.min.js"></script>

<!-- Specific version -->
<script src="https://unpkg.com/[email protected]/dist/kton-sdk.min.js"></script>

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Workflow

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes
  4. Run tests: npm run test
  5. Commit changes: git commit -m 'Add amazing feature'
  6. Push to branch: git push origin feature/amazing-feature
  7. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🆘 Support

🏗️ Built With

📊 Bundle Size

  • ESM: 680.36 kB (129.47 kB gzipped)
  • UMD: 339.48 kB (99.76 kB gzipped)
  • TypeScript Declarations: Full type support included