Configurable client options ship in v1.2.0. See the Changelog before upgrading.
Initialize the client
Your Blnk client is the single entry point to everything: ledgers, balances, transactions, reconciliation, and more. Configure it once when your app starts, then use it everywhere. Create a helper that reads your base URL and API key from the environment, then passes functional options for timeout and retries:client.go
create-ledger.go
client.Ledger, client.LedgerBalance, and other services.
Authentication
NewClient takes a base URL and an optional API key pointer. The SDK sends the key on every request in the X-Blnk-Key header when you pass a non-nil pointer.
How you set the API key depends on whether Core runs in secure mode:
- Secure mode
- Auth disabled
When
server.secure is enabled, pass a pointer to your API key as the second argument.Secure Blnk
Secure mode, master key, and server hardening.
Scoped API keys
Owner-scoped keys and permission limits.
Timeouts and retries
When connections fail, Core restarts, or requests hang, the SDK handles it without blocking your app. Pass functional options toNewClient to tune behavior:
When to tune these:
- Keep defaults if you’re making fast, local calls and want to fail fast.
- Increase
WithTimeoutif you’re running large batch requests that may take a while to complete synchronously. - Increase
WithRetryif you’re reading data across an unreliable network.
Retries apply to idempotent
GET requests and retryable network failures. POST, PUT, and DELETE are not retried on HTTP errors.Custom logger
By default, the SDK logs retry and transport events through a built-in logger that writes to stdout withINFO: and ERROR: prefixes.
Pass a type that implements blnkgo.Logger to route these messages to your own logging system instead of stdout.
Building transaction requests
Callclient.Transaction.Create and pass a blnkgo.CreateTransactionRequest struct. It has two parts:
ParentTransactionholds the core transaction fields: amount, currency, source, destination, reference, and metadata.- Top-level fields control how the request is processed, such as
AllowOverdraft,Inflight, andScheduledFor.
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.CreateLedgerRequest to client.Ledger.Create, CreateLedgerBalanceRequest to client.LedgerBalance.Create, and so on.
JSON field names
Go struct fields use PascalCase, likeMetaData 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. Per-method Go SDK pages list the Go request and response field names for each call.
Precise amounts
TransactionPreciseAmount fields use *big.Int in the Go SDK. Pass minor units with big.NewInt(...), for example big.NewInt(75000) with Precision: 100 for 750.00. Add import "math/big" at the top of your file when you use big.NewInt.
You can still use Amount as a float64 when you prefer float-style values; the SDK and Core apply Precision to derive precise_amount.
Date and time fields
Fields such asDOB, 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 so zero values omit from JSON.