ApiBTC
APIBTC: Unlock Instant Bitcoin Payments for Your AI & Apps
Effortlessly weave the power of the Bitcoin Lightning Network into your AI agents, applications, and automated services using elegantly simple Python and JavaScript APIs.
Unleash the Power of Programmable Money
The Bitcoin Lightning Network represents a paradigm shift: near-instant, low-fee Bitcoin transactions at scale. But harnessing this power often involves navigating complex protocols, channel management, and node operations.
APIBTC is your streamlined gateway. We abstract the intricate details, providing clean, developer-centric interfaces so you can focus on innovation, not infrastructure. Integrate programmable Bitcoin payments to:
- đ Supercharge AI Agents: Grant your autonomous agents the ability to transact directly â paying for APIs, accessing premium data streams, or interacting with other agents on a value-for-value basis.
- đ° Monetize Effortlessly: Accept instant Bitcoin payments for your SaaS, APIs, digital content, or any service, opening up global, censorship-resistant revenue streams.
- đĄ Build the Future: Pioneer novel applications in DeFi, gaming, IoT micropayments, creator economies, and automated systems where instant value transfer is key.
Why Developers Choose APIBTC
We built APIBTC with the developer experience as our top priority. Hereâs what sets it apart:
- ⥠Truly Instant Payments: Tap into the Lightning Networkâs sub-second settlement times and negligible fees. Perfect for micropayments and high-throughput scenarios where traditional finance lags behind.
- đ¤ Designed for Automation: Minimal, predictable functions make integrating payments into complex AI logic, scripts, or backend services a breeze. Think
addinvoice()
,sendpayment()
,getinvoice()
. Simple. - đť Fluent in Your Language: Get native, idiomatic libraries for Python and JavaScript â the dominant languages in AI, machine learning, and web development. No awkward wrappers, just clean code.
- đ One-Click Deployment: Get the full stack running instantly with a single Docker container. No complex setup, no dependency management â just pull the image and youâre ready to build.
- đ Truly Permissionless: No account creation, no KYC, no approval process. Simply generate a private key locally and start using the API immediately. True to Bitcoinâs core principles.
- đ Transparent & Community-Driven: As fully open-source software (Apache 2.0 Licensed), you have complete visibility. Inspect the code, contribute improvements, and join a community building the future of Bitcoin integration.
Imagine the PossibilitiesâŚ
APIBTC isnât just a library; itâs an enabler for groundbreaking ideas:
- Autonomous AI Researchers: Picture an AI agent dynamically purchasing specialized compute time on decentralized networks or paying for exclusive datasets â all via seamless Lightning transactions.
- Micropayment-Powered Media: Content creators finally escaping ad-dependency, receiving satoshis instantly per article view, video watch, or podcast listen.
- Self-Sustaining IoT: Smart devices autonomously paying for their own bandwidth, data storage, or critical firmware updates using earned or allocated Bitcoin.
- High-Frequency Trading Bots: Automated systems settling trades or paying for real-time data feeds directly over Lightning, minimizing counterparty risk and delays.
- Usage-Based API Billing: Offering your API with granular, pay-as-you-go pricing, settled instantly without costly payment processor overhead.
Advanced Features: HODL Invoices
APIBTC now supports HODL invoices, a powerful feature that enables escrow-like functionalities in the Lightning Network.
What are HODL Invoices?
HODL invoices allow for conditional payments where funds are locked until a specific condition is met. Unlike standard invoices that settle immediately, HODL invoices remain in a pending state until explicitly settled with a preimage.
Key Benefits:
- Escrow Capabilities: Create trustless escrow arrangements where funds are only released when predefined conditions are met.
- Conditional Payments: Enable payments that only complete when a specific action occurs or verification is provided.
- Enhanced Security: Add an additional layer of protection for high-value transactions or complex payment scenarios.
How It Works:
- The recipient creates a HODL invoice with a random or specific hash
- The payer sends payment to the HODL invoice
- Funds remain locked (but committed) until the recipient reveals the preimage
- The recipient settles the invoice by providing the preimage through the SettleInvoice method
Use Cases:
- Marketplace Escrow: Hold buyer funds until seller confirms shipment or delivery
- Service Completion Verification: Release payment only when a service is confirmed complete
- Multi-stage Transactions: Enable complex payment flows requiring verification steps
- Atomic Swaps: Facilitate cross-chain cryptocurrency exchanges
API Documentation
APIBTC provides comprehensive API documentation through Swagger.
Important Notice: The API documentation and testing environment operates on Bitcoinâs regtest network.
What is Regtest?
Regtest (Regression Test Mode) is a local testing environment where developers can create blocks on demand, control the network conditions, and test Bitcoin applications without using real Bitcoin. Itâs completely isolated from the mainnet and testnet networks.
â ď¸ Warning: Do not send real Bitcoin to any addresses generated in this environment!
Any real Bitcoin sent to regtest addresses will be lost permanently. The regtest environment is designed exclusively for development and testing purposes.
Using the Swagger Documentation
The Swagger UI provides:
- Interactive documentation for all API endpoints
- The ability to test API calls directly from your browser
- Request and response examples
- Parameter descriptions and requirements
- Authentication information
This makes it easy to understand the API capabilities before implementing them in your code.
See APIBTC in Action: AI Agent Demo
Watch how an AI agent can seamlessly interact with the Bitcoin Lightning Network using APIBTC:
This demonstration showcases how AI agents can autonomously create invoices, process payments, and interact with the Lightning Network - all through the simple and intuitive APIBTC interface.
Launch in Minutes: Your First Lightning Integration
Getting started with APIBTC is incredibly straightforward. Follow these simple steps to integrate Lightning payments into your project.
1. Install the Library
Grab the package using your environmentâs standard tool:
# For Python environments
pip install apibtc
# For Node.js / JavaScript environments
npm install @thehyperlabs/apibtc
# For .NET environments
dotnet add package ApiBtc.Client
2. Initialize and Interact
Once installed, initialize the client with your credentials and start interacting with the Lightning Network. Hereâs a taste:
Python Example
from apibtc import Wallet
from mnemonic import Mnemonic
from bip32utils import BIP32Key
# Declare API url
BASE_URL = "API_BASE_URL"
# Create two wallets
# Wallet 1 - Invoice Creator
mnemon1 = Mnemonic('english')
words1 = mnemon1.generate(128)
private_key1 = BIP32Key.fromEntropy(mnemon1.to_seed(words1)).PrivateKey().hex()
wallet1 = Wallet(base_url=BASE_URL, privkey=private_key1)
# Wallet 2 - Invoice Payer
mnemon2 = Mnemonic('english')
words2 = mnemon2.generate(128)
private_key2 = BIP32Key.fromEntropy(mnemon2.to_seed(words2)).PrivateKey().hex()
wallet2 = Wallet(base_url=BASE_URL, privkey=private_key2)
# Payment flow
# Create invoice with wallet1
invoice = wallet1.addinvoice(satoshis=1000, memo="Payment from wallet2", expiry=3600)
# Pay invoice with wallet2
wallet2.sendpayment(paymentrequest=invoice['payment_request'], timeout=30, feelimit=100)
# Check balances after payment
print("Wallet1 balance:", wallet1.getbalance())
print("Wallet2 balance:", wallet2.getbalance())
JavaScript Example
const { Wallet } = require('@thehyperlabs/apibtc');
const bip39 = require('bip39');
const hdkey = require('hdkey');
// Declare API url
const BASE_URL = "API_BASE_URL";
// Create two wallets
// Wallet 1 - Invoice Creator
const mnemonic1 = bip39.generateMnemonic(128);
const seed1 = bip39.mnemonicToSeedSync(mnemonic1);
const privateKey1 = hdkey.fromMasterSeed(seed1).privateKey.toString('hex');
const wallet1 = new Wallet(BASE_URL, privateKey1);
// Wallet 2 - Invoice Payer
const mnemonic2 = bip39.generateMnemonic(128);
const seed2 = bip39.mnemonicToSeedSync(mnemonic2);
const privateKey2 = hdkey.fromMasterSeed(seed2).privateKey.toString('hex');
const wallet2 = new Wallet(BASE_URL, privateKey2);
// Payment flow
// Create invoice with wallet1
const invoice = await wallet1.addinvoice(1000, "Payment from wallet2", 3600);
// Pay invoice with wallet2
await wallet2.sendpayment(invoice.paymentRequest, 30, 100);
// Check balances after payment
console.log("Wallet1 balance:", await wallet1.getbalance());
console.log("Wallet2 balance:", await wallet2.getbalance());
C# Example
using System;
using NBitcoin;
using ApiBtc.Client;
class Program
{
static void Main()
{
// Declare API url
const string BASE_URL = "API_BASE_URL";
// Create two wallets
// Wallet 1 - Invoice Creator
Mnemonic mnemonic1 = new Mnemonic(Wordlist.English, WordCount.Twelve);
ExtKey hdRoot1 = mnemonic1.DeriveExtKey();
string privateKey1 = hdRoot1.PrivateKey.ToHex();
var wallet1 = new Wallet(BASE_URL, privateKey1);
// Wallet 2 - Invoice Payer
Mnemonic mnemonic2 = new Mnemonic(Wordlist.English, WordCount.Twelve);
ExtKey hdRoot2 = mnemonic2.DeriveExtKey();
string privateKey2 = hdRoot2.PrivateKey.ToHex();
var wallet2 = new Wallet(BASE_URL, privateKey2);
// Payment flow
// Create invoice with wallet1
var invoice = await wallet1.AddInvoice(1000, "Payment from wallet2", 3600);
// Pay invoice with wallet2
await wallet2.SendPayment(invoice.PaymentRequest, 30, 100);
// Check balances after payment
Console.WriteLine($"Wallet1 balance: {await wallet1.GetBalance()}");
Console.WriteLine($"Wallet2 balance: {await wallet2.GetBalance()}");
}
}
Shape the Future: Contribute to APIBTC
APIBTC thrives on community collaboration. Whether youâre fixing a typo, improving documentation, tackling a bug, or implementing a new feature, your contributions are valuable and welcome!
- Find an Issue: Check the issue tracker for open tasks or propose your own enhancement.
- Fork & Code: Fork the repository, create your feature branch, and start coding!
- Submit a Pull Request: Once ready, submit a PR for review.
Letâs build the best Bitcoin Lightning integration tool together! Visit the APIBTC GitHub Repository to get involved.
Like APIBTC? Give us a star on GitHub!
Star