ApiBTC

APIBTC: Unlock Instant Bitcoin Payments for Your AI & Apps

PyPI version npm version .NET version License

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:


Why Developers Choose APIBTC

We built APIBTC with the developer experience as our top priority. Here’s what sets it apart:


Imagine the Possibilities…

APIBTC isn’t just a library; it’s an enabler for groundbreaking ideas:


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:

How It Works:

  1. The recipient creates a HODL invoice with a random or specific hash
  2. The payer sends payment to the HODL invoice
  3. Funds remain locked (but committed) until the recipient reveals the preimage
  4. The recipient settles the invoice by providing the preimage through the SettleInvoice method

Use Cases:


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:

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!

  1. Find an Issue: Check the issue tracker for open tasks or propose your own enhancement.
  2. Fork & Code: Fork the repository, create your feature branch, and start coding!
  3. 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