All Articles
BitcoinLightning NetworkFinTechM-PesaKenya

BTCPay Server in Kibera: Building Bitcoin Infrastructure for a Circular Economy

How I deployed Lightning Network payment infrastructure in one of Africa's largest informal settlements, processing 847+ BTC transactions and bridging M-Pesa with Bitcoin.

September 20, 20254 min read

Why Bitcoin in an Informal Settlement?

Kibera is home to roughly 250,000 people in an area smaller than New York's Central Park. Most residents are unbanked. Mobile money (M-Pesa) is the primary financial tool, but it carries transaction fees that disproportionately affect small transactions — the exact kind of transactions Kibera's economy runs on.

The thesis behind Afribit was simple: Bitcoin's Lightning Network can process micropayments at near-zero cost. If we could bridge M-Pesa to Lightning, we could reduce transaction friction for the small businesses that form the backbone of Kibera's economy.

The Technical Stack

BTCPay Server: Self-Sovereign Payment Processing

We chose BTCPay Server over custodial solutions for a fundamental reason: trust. In a community where financial institutions have historically failed people, asking them to trust another intermediary was a non-starter. BTCPay Server runs on our infrastructure, processes payments without intermediaries, and gives us full control over the payment flow.

The deployment ran on a modest VPS:

  • BTCPay Server with PostgreSQL backend
  • LND (Lightning Network Daemon) for Lightning channel management
  • Nginx reverse proxy with Let's Encrypt TLS
  • Docker Compose orchestrating all services

The M-Pesa Bridge

This was the hardest engineering challenge. M-Pesa's API is designed for traditional mobile money flows — send money, receive money, pay bill. It has no concept of cryptocurrency. We built a bridge service that:

  1. Merchant generates a Lightning invoice via BTCPay Server
  2. Customer initiates M-Pesa payment to our paybill number
  3. Webhook receives M-Pesa confirmation with transaction amount and reference
  4. Bridge service converts KES → BTC at real-time exchange rate from multiple sources
  5. Lightning payment settles the original invoice
  6. Both parties receive confirmation — merchant in BTC, customer sees M-Pesa debit

The entire flow completes in under 10 seconds. The customer's experience is identical to a normal M-Pesa payment. The merchant receives Bitcoin.

Channel Management

Lightning Network channels require active management. Opening a channel costs an on-chain transaction fee. Closing a channel costs another. In between, the channel has a fixed capacity that determines how much can flow through it.

For Kibera's transaction patterns — many small payments throughout the day — we needed:

  • Large inbound capacity from well-connected routing nodes
  • Automated rebalancing when channels became one-sided
  • Monitoring alerts for low channel capacity before transactions start failing

We wrote a custom channel management daemon that monitored all channels every 5 minutes and triggered rebalancing when any channel dropped below 20% capacity on either side.

Adoption Challenges

The Trust Barrier

The first two months were brutal. Despite Kibera's tech-savvy youth population, Bitcoin carried stigma. "Isn't that what scammers use?" was the most common question. We countered this with:

  • In-person workshops at community centers — showing, not telling
  • Starting with merchants, not consumers — when your local kiosk accepts Bitcoin, it becomes normal
  • Transparent transaction receipts — every payment generated a receipt showing exact exchange rate, fees (or lack thereof), and settlement status

The Volatility Problem

Bitcoin's price volatility is an abstract concern for investors. For a vegetable vendor in Kibera, receiving payment in an asset that might lose 10% overnight is existential. We solved this by offering instant conversion: the moment a Lightning payment settles, the merchant can trigger M-Pesa withdrawal at the current rate. Hold time was measured in seconds, not hours.

The Numbers After 12 Months

  • 847 BTC transactions processed through the platform
  • 2,000+ Lightning invoices generated
  • 43 active merchants in the Kibera ecosystem
  • Average transaction: ~500 KES (~$4 USD) — true micropayments
  • Transaction fees: under 1% vs. M-Pesa's 1-3% for equivalent transfers

Lessons for Emerging Market FinTech

Infrastructure before features. We spent 60% of development time on reliability — monitoring, alerting, automated recovery. In a market where downtime means lost trust, infrastructure isn't boring — it's the product.

Compliance is non-negotiable. Kenya's Central Bank has evolving regulations around cryptocurrency. We maintained full KYC/AML compliance through our M-Pesa integration (which requires registered SIM cards) and kept detailed transaction logs. Working with, not against, regulators.

Design for the worst device. Our merchant dashboard ran on phones that barely handle WhatsApp. Every page was under 500KB. Every interaction worked without JavaScript (progressively enhanced). Loading states were instant and clear.

The project proved that Bitcoin infrastructure can serve real communities with real economic needs — not as a speculative asset, but as payment rails that reduce friction in daily commerce.

Related Case Study

Read the full case study