Integrating cryptocurrency payments into your application has never been easier, thanks to modern tools like the Crypto Bot API—a robust, up-to-date TypeScript client library designed specifically for interacting with Telegram’s Crypto Pay API via the popular CryptoBot service. Whether you're building on Node.js or targeting browser environments, this lightweight yet powerful library streamlines communication with Telegram's crypto infrastructure, enabling seamless payment handling, balance checks, transaction monitoring, and more.
This guide dives deep into how developers can install, configure, and leverage the crypto-bot-api
package effectively across different platforms while maintaining best practices in code quality and security.
Installing Crypto Bot API
Getting started is straightforward using standard JavaScript package managers. To add the library to your project, run one of the following commands:
npm install crypto-bot-api
or with Yarn:
yarn add crypto-bot-api
For front-end applications, you can either import the module directly (if using a bundler like Webpack or Vite) or include pre-built bundles located in the dist
directory. These UMD builds are ideal for quick integration into static websites or legacy projects without complex build setups.
👉 Discover how to integrate secure crypto payments into your app today.
Using the Library in Node.js and Browsers
In Node.js
Once installed, initialize the client with your bot token—typically obtained through the Telegram CryptoBot interface—and begin making API calls immediately:
const CryptoBotAPI = require('crypto-bot-api');
const client = new CryptoBotAPI('1234:AAA...AAA'); // Replace with your actual token
const me = await client.getMe();
console.log(me);
The getMe()
method returns information about your bot, confirming that authentication works correctly. From there, you can proceed to create invoices, check transaction statuses, retrieve balances, and respond to user actions programmatically.
In Browser Environments
Browser usage follows a similar pattern:
var client = new CryptoBotAPI('1234:AAA...AAA');
client.getMe().then(function(me) {
console.log(me);
});
⚠️ Important Note: As of version 0.3.5 (March 2025), the Crypto Pay API does not include the Access-Control-Allow-Origin
header in its responses. This means direct API calls from browser-based web pages will be blocked due to CORS restrictions. However, the library still functions properly within browser extensions, Electron apps, and other environments where CORS policies are relaxed or configurable.
For full functionality in public-facing websites, consider routing requests through a backend proxy server.
Handling Real-Time Updates via Webhooks
To react dynamically to incoming payments or user interactions, the Crypto Pay API supports webhook notifications. The crypto-bot-api
library provides two primary methods for receiving these updates:
- Built-in HTTP/HTTPS Server: Use the
createServer()
method from theClientEmitter
class to launch a minimal server that listens for incoming webhook events. - Express.js Middleware: Integrate seamlessly with Express-based backends using the provided middleware function for clean, modular routing.
Example setups are available in the GitHub examples folder, particularly those prefixed with webhooks-
.
📌 Remember: You must enable webhooks in your CryptoBot app settings. If using a self-signed SSL certificate, upload it through the CryptoBot API configuration panel to ensure secure delivery.
👉 Learn how real-time crypto transaction handling boosts user engagement.
Core Features and Use Cases
The crypto-bot-api
unlocks several critical capabilities for developers building crypto-powered services:
- Payment Invoicing: Generate instant payment links or invoices in multiple cryptocurrencies supported by Telegram CryptoBot (e.g., BTC, ETH, USDT).
- Balance Monitoring: Retrieve wallet balances programmatically.
- Transaction History: Fetch recent transactions and verify payment confirmations.
- User Management: Identify users via Telegram IDs and personalize experiences.
- Event-Driven Architecture: React instantly to successful payments using webhooks.
These features make it ideal for use in:
- E-commerce integrations
- Donation platforms
- SaaS subscription models
- Gaming and digital content marketplaces
Building and Customizing Locally
Developers interested in contributing or customizing the library can clone the repository and build components locally:
git clone https://github.com/sergeiivankov/crypto-bot-api
cd crypto-bot-api
npm install
Available build scripts include:
npm run build-lib
: Compiles source code for Node.js (output in/lib
)npm run build-dist
: Generates browser-ready bundles (output in/dist
)npm run build-docs
: Builds documentation from JSDoc commentsnpm run build
: Runs all build tasks
For active development, use watch scripts:
npm run watch-lib # Watch and rebuild Node.js version
npm run watch-dist # Watch and rebuild browser bundles
npm run watch-docs # Auto-generate updated docs
npm run watch # Watch everything
Documentation and Learning Resources
Comprehensive documentation is hosted at sergeiivankov.github.io/crypto-bot-api, offering detailed class references and method signatures.
Recommended starting points:
- For Node.js developers: Begin with the
ClientEmitter
class - For browser developers: Refer to the
Client
class
Additional resources:
FAQ: Frequently Asked Questions
Q: Can I use this library in a React or Vue.js application?
A: Yes—but due to CORS limitations, direct browser calls won’t work on public websites. Use a backend proxy or restrict usage to Electron/desktop apps.
Q: Is TypeScript support built-in?
A: Absolutely. The entire library is written in TypeScript, providing full type safety and IntelliSense support out of the box.
Q: What cryptocurrencies are supported?
A: The supported coins depend on Telegram CryptoBot’s current offerings, typically including BTC, ETH, USDT, BNB, and others.
Q: How do I test webhooks during development?
A: Use tools like ngrok to expose your local server publicly and configure the forwarding URL in your CryptoBot settings.
Q: Does the library support error handling and retries?
A: It exposes raw responses and errors; retry logic should be implemented at the application level based on your needs.
Q: Is this library officially affiliated with Telegram?
A: No. It is a third-party open-source project maintained independently of Telegram or CryptoBot.
Supported Environments
The library ensures broad compatibility across modern platforms:
- Node.js: v12 and above
- Browsers: Chrome 32+, Firefox 29+, Edge 12+, Safari 8+, Safari iOS 8+, Android Browser 4.4.4+
This wide support makes it suitable for both legacy system integration and cutting-edge web applications.
Code Quality and Contribution Guidelines
Maintained with strict standards, the project uses ESLint for consistent code formatting and enforces thorough documentation for every public API. Contributors must ensure their pull requests pass linting checks and update relevant documentation accordingly.
License
This project is licensed under the permissive MIT License, allowing free use, modification, and distribution for personal and commercial projects alike.
👉 Explore advanced crypto development tools and grow your project now.