Skip to main content
The Blnk Go SDK is the official Go client for Blnk Core. This page gets you from install to a working transaction. For detailed documentation on each API, reference the Core documentation.

Quick start

In a few minutes, you’ll have a Go app moving money on your Blnk ledger. That’s the starting point for wallets, transfers, and the rest of your product.
1

Launch Blnk

You need a running Blnk Core instance before using the SDK.

Install Blnk

Local install or Blnk Cloud
2

Install the Blnk Go SDK

Create a Go project and install the SDK. You need Go 1.22 or later.
bash
go mod init blnk-quickstart
go get github.com/blnkfinance/blnk-go
3

Client initialization

Parse your Blnk base URL and create a client. Pass a pointer to your API key when your instance requires authentication. The SDK sends it as the X-Blnk-Key header.Use nil when running locally without auth.
client.go
baseURL, _ := url.Parse("http://localhost:5001/")
apiKey := "your_api_key"
client := blnkgo.NewClient(
    baseURL,
    &apiKey,
    blnkgo.WithTimeout(10*time.Second),
    blnkgo.WithRetry(2),
)
4

Create your first transaction

Create main.go, paste the script below, and run it:
main.go
package main

import (
	"fmt"
	"net/url"
	"time"

	blnkgo "github.com/blnkfinance/blnk-go"
)

func main() {
	baseURL, _ := url.Parse("http://localhost:5001/")
	client := blnkgo.NewClient(
		baseURL,
		nil,
		blnkgo.WithTimeout(10*time.Second),
		blnkgo.WithRetry(2),
	)

	transaction, resp, err := client.Transaction.Create(blnkgo.CreateTransactionRequest{
		ParentTransaction: blnkgo.ParentTransaction{
			Amount:      1000,
			Reference:   "first_txn_001",
			Currency:    "USD",
			Precision:   100,
			Source:      "@FundingPool",
			Destination: "@MyBalance",
			Description: "My first Blnk transaction",
		},
		AllowOverdraft: true,
	})
	if err != nil {
		fmt.Printf("Error creating transaction: %v\n", err)
		return
	}

	fmt.Printf("Transaction ID: %s\n", transaction.TransactionID)
	fmt.Printf("Status: %s\n", transaction.Status)
	fmt.Printf("HTTP status: %d\n", resp.StatusCode)
}
Run the script:
bash
go run main.go
Your script prints the transaction ID when it succeeds. Verify the record with the CLI or in Blnk Cloud.
bash
blnk transactions list

Error handling

Every SDK method returns three values: the result, the HTTP response, and an error.
import "errors"

ledger, resp, err := client.Ledger.Create(body)
if err != nil {
    var apiErr *blnkgo.ApiErrorResponse
    if errors.As(err, &apiErr) {
        fmt.Printf("API error %d: %s\n", apiErr.Status, apiErr.Body)
    }
    return err
}
fmt.Printf("HTTP status: %d\n", resp.StatusCode)
When Blnk returns a 4xx or 5xx status, the SDK wraps the response in ApiErrorResponse. Use errors.As to read the status code and response body. On success, inspect resp.StatusCode for logging or metrics.

Using the SDK

Reference the Core documentation to understand how each API works. This section shows how those APIs are organized in the Go SDK.

Client structure

NewClient returns a client with one service per resource:
  • client.Ledger
  • client.LedgerBalance
  • client.Transaction
  • client.BalanceMonitor
  • client.Identity
  • client.Search
  • client.Reconciliation
  • client.Metadata
Call methods on the service that matches the resource you need. The endpoint map lists each method and links to its API reference page.

Building transaction requests

Call client.Transaction.Create and pass a blnkgo.CreateTransactionRequest struct. It has two parts:
  1. ParentTransaction holds the core transaction fields: amount, currency, source, destination, reference, and metadata.
  2. Top-level fields control how the request is processed, such as AllowOverdraft, Inflight, and ScheduledFor.
ParentTransaction is an embedded struct in the Go SDK, not a field in the API request body. The API expects flat JSON with fields like amount and source at the root.Do not confuse this struct with the API response field parent_transaction, which is a transaction ID linking related records such as inflight commits or split distributions.
blnkgo.CreateTransactionRequest{
    ParentTransaction: blnkgo.ParentTransaction{
        Amount:      1000,
        Precision:   100,
        Currency:    "USD",
        Source:      "bln_28f25ef6-2e0d-4fa6-891c-37fc409d654e",
        Destination: "bln_86ba7976-499d-4282-955e-a7c2abf5db12",
        Reference:   "payment_001",
    },
    AllowOverdraft: true,
}
Transactions are the exception. Every other resource uses a single request struct with no nesting. Pass CreateLedgerRequest to client.Ledger.Create, CreateLedgerBalanceRequest to client.LedgerBalance.Create, and so on.

JSON field names

Go struct fields use PascalCase, like MetaData and LedgerID. These map to the API’s snake_case JSON fields (meta_data, ledger_id). You should always use the Go field names in your code.

Date and time fields

Fields such as DOB, EffectiveDate, ScheduledFor, InflightCommitDate, and historical balance timestamps use time.Time (or *time.Time). Parse ISO 8601 strings with time.Parse(time.RFC3339, "...")—for example "2024-04-22T15:28:03Z" or "2024-12-21T01:36:46+01:00"—then pass the resulting value (use a pointer when the field is optional).

Client options

Pass optional settings to NewClient as functional options:
  1. WithTimeout sets the HTTP timeout.
  2. WithRetry sets how many times the client retries failed requests.
  3. WithLogger attaches a custom logger.
apiKey := os.Getenv("BLNK_API_KEY")
client := blnkgo.NewClient(
    baseURL,
    &apiKey,
    blnkgo.WithTimeout(30*time.Second),
    blnkgo.WithRetry(3),
)

Endpoint map

Each SDK method calls a Blnk Core HTTP endpoint. Use this map to find the SDK method for an operation and open its reference page.
SDK methodAPI Reference
client.Ledger.CreateCreate ledger
client.Ledger.GetGet ledger
client.Ledger.ListGet ledger
ledger, resp, err := client.Ledger.Create(blnkgo.CreateLedgerRequest{
    Name: "Customer accounts",
})

Where to find examples

Go SDK examples

Escrow, savings, cards, and reconciliation.

Core tutorials

Step-by-step use case guides

Ledgers

Group and organize balances

Balances

Wallets, accounts, and stores of value

Need help?

We are very happy to help you make the most of Blnk, regardless of whether it is your first time or you are switching from another tool. To ask questions or discuss issues, please contact us or join our Discord community.

Issue reporting and contributions

The Go SDK is open-source on GitHub, and we welcome community issues and pull requests. If you run into problems installing or using the SDK, report them on GitHub. If an endpoint is documented in the API reference but missing from the Go SDK, we encourage opening an issue or submitting a pull request to help improve SDK coverage.