BchainPayBchainPay

Go SDK


title: "Go SDK" description: "Official github.com/bchainpay/bchainpay-go SDK — context-aware, idiomatic Go." section: "SDKs" order: 3 updated: "2026-04-18" sourcePath: "content/docs/sdks/go.mdx"

The Go SDK is context-aware, uses the standard net/http client, and exposes typed structs for every API resource.

Install

go get github.com/bchainpay/bchainpay-go

Requires Go 1.22+.

Initialize

import "github.com/bchainpay/bchainpay-go"
 
client := bchainpay.NewClient(os.Getenv("BCHAINPAY_API_KEY"))

Create a payment intent

ctx := context.Background()
 
intent, err := client.PaymentIntents.Create(ctx, &bchainpay.PaymentIntentParams{
    AmountCents:        4999,
    Currency:           "USD",
    SettlementCurrency: "USDC",
    Network:            "polygon",
    Reference:          "INV-2026-001",
})
if err != nil {
    log.Fatal(err)
}
fmt.Println(intent.Address)

Verify a webhook

import "github.com/bchainpay/bchainpay-go/webhooks"
 
http.HandleFunc("/webhooks", func(w http.ResponseWriter, r *http.Request) {
    body, _ := io.ReadAll(r.Body)
    if !webhooks.Verify(body, r.Header.Get("BchainPay-Signature"), os.Getenv("BCHAINPAY_WEBHOOK_SECRET")) {
        http.Error(w, "bad signature", http.StatusBadRequest)
        return
    }
    // ... handle event
    w.WriteHeader(http.StatusOK)
})
Last updated Edit on GitHub