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.
go get github.com/opd-ai/paywall
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))
}
type Config struct {
PriceInBTC float64
TestNet bool
Store Store
PaymentTimeout time.Duration
}
NewMemoryStore()
: In-memory payment tracking (default)NewFileStore()
: Filesystem-based persistent storage// 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)
// Memory Store
store := paywall.NewMemoryStore()
// File Store
store := paywall.NewFileStore(paywall.FileStoreConfig{
DataDir: "/var/lib/paywall/data",
EncryptionKey: key,
})
Perfect for:
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.
If you find this project useful, consider supporting the developer:
Monero Address: 43H3Uqnc9rfEsJjUXZYmam45MbtWmREFSANAWY5hijY4aht8cqYaT2BCNhfBhua5XwNdx9Tb6BEdt4tjUHJDwNW5H7mTiwe
Bitcoin Address: bc1qew5kx0srtp8c4hlpw8ax0gllhnpsnp9ylthpas
MIT License - see LICENSE file for details
Created and maintained by the OPD AI team.