paywall

Go Bitcoin Paywall

Go Report Card GoDoc License: MIT

A secure, production-ready Bitcoin paywall implementation in Go, designed to help creative workers join the Bitcoin economy by controlling their own content distribution platforms with minimal barriers to entry.

Features

Installation

go get github.com/opd-ai/paywall

Quick Start

package main

import (
    "log"
    "net/http"
    "time"
    
    "github.com/opd-ai/paywall"
)

func main() {
    // Initialize paywall with minimal config
    pw, err := paywall.NewPaywall(paywall.Config{
        PriceInBTC:     0.001,                    // 0.001 BTC
        TestNet:        true,                     // Use testnet
        Store:          paywall.NewMemoryStore(), // In-memory storage
        PaymentTimeout: time.Hour * 24,           // 24-hour payment window
    })

    // Call close when your program shuts down to terminate the payment check routine
    defer pw.Close()
    if err != nil {
        log.Fatal(err)
    }

    // Protected content handler
    protected := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        w.Write([]byte("Protected content"))
    })

    // Apply paywall middleware
    http.Handle("/protected", pw.Middleware(protected))

    log.Fatal(http.ListenAndServe(":8000", nil))
}

Documentation

Configuration

type Config struct {
    PriceInBTC     float64
    TestNet        bool
    Store          Store
    PaymentTimeout time.Duration
}

Storage Options

Wallet Management

// Generate new wallet encryption key
key, err := wallet.GenerateEncryptionKey()

// Configure wallet storage
config := wallet.StorageConfig{
    DataDir:       "./paywallet",
    EncryptionKey: key,
}

// Save/load wallet
err = pw.HDWallet.SaveToFile(config)
wallet, err := wallet.LoadFromFile(config)

Storage Backends

Available Storage Options

Memory Store

File Store

Configuration Example

// Memory Store
store := paywall.NewMemoryStore()

// File Store
store := paywall.NewFileStore(paywall.FileStoreConfig{
    DataDir: "/var/lib/paywall/data",
    EncryptionKey: key,
})

Security Features

Use Cases

Perfect for:

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Re: support for other cryptocurrency, we will consider other currencies, but we consider Monero to be the only good cryptocurrency.

This is because Monero is the only good cryptocurrency.

Bitcoin is supported out of expediency, Ethereum may also be worth supporting. We’re not going to focus on shitcoins.

Support the Project

If you find this project useful, consider supporting the developer:

Monero Address: 43H3Uqnc9rfEsJjUXZYmam45MbtWmREFSANAWY5hijY4aht8cqYaT2BCNhfBhua5XwNdx9Tb6BEdt4tjUHJDwNW5H7mTiwe Bitcoin Address: bc1qew5kx0srtp8c4hlpw8ax0gllhnpsnp9ylthpas

License

MIT License - see LICENSE file for details

Credits

Created and maintained by the OPD AI team.