Skip to content

About

Migrate a Formance Ledger (v2) into Blnk safely, resumably and verifiably. Replay, snapshot or hybrid strategies, idempotent writes and balance reconciliation. Go CLI and library with no dependencies.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

formance2blnk

Go Reference Release Go Report Card Docs License: MIT

Migrate a Formance Ledger (v2 API) into Blnk — safely, resumably and verifiably.

formance2blnk is both a CLI and a Go library with zero third-party dependencies.

  • Three strategies — full history replay, opening-balance snapshot, or hybrid (snapshot at a cutoff + replay after it).
  • Idempotent — every Blnk transaction gets a deterministic reference; interrupted runs resume from a checkpoint without double-posting.
  • Atomic — multi-posting Formance transactions are written as atomic Blnk bulk batches (up to batch_size postings).
  • Exact amounts — arbitrary-precision integers end to end (USD/2 → currency USD, precision 100, precise_amount).
  • Flexible mapping — glob rules route Formance addresses to Blnk ledgers, @indicator balances, or skip them; or plug in your own Mapper.
  • Reconciliation — compares every balance (and optionally credit/debit volumes) and exits non-zero on drift, for CI gates and cutover checklists.

Why

It was built to split a combined fiat and crypto Formance ledger in two. A surge in crypto activity could slow the fiat rails, and keeping both asset classes in one ledger widened the regulatory audit scope. The fix was full separation: fiat stays on Formance, and crypto moves with all its history to a standalone Blnk instance. formance2blnk is the pipeline that moves it and proves nothing was lost. See Why formance2blnk for the full story and a carve-out configuration.

Documentation

📖 The full documentation lives at otyang.github.io/formance2blnk.

Start here Guides Reference
Why formance2blnk Concepts Configuration
Getting started Strategies CLI
Examples Mapping Go library
Troubleshooting Reconciliation Compatibility
Changelog Cutover runbook API on pkg.go.dev

Install

# Go toolchain (1.22+)
go install github.com/otyang/formance2blnk/cmd/formance2blnk@latest

# Docker (linux/amd64 and linux/arm64)
docker run --rm ghcr.io/otyang/formance2blnk:latest help

# Library
go get github.com/otyang/formance2blnk@latest

Prebuilt binaries for Linux, macOS and Windows (amd64/arm64) with checksums are attached to every GitHub release.

Quick start (CLI)

formance2blnk init > formance2blnk.json        # edit URLs, ledgers and mapping
formance2blnk validate                          # check the config
formance2blnk plan                              # dry run: what would be created
formance2blnk migrate                           # run it (Ctrl-C safe, re-runnable)
formance2blnk reconcile -volumes                # prove the ledgers match

Quick start (library)

package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"github.com/otyang/formance2blnk/blnk"
	"github.com/otyang/formance2blnk/formance"
	"github.com/otyang/formance2blnk/mapping"
	"github.com/otyang/formance2blnk/migrator"
	"github.com/otyang/formance2blnk/state"
)

func main() {
	ctx := context.Background()
	src, _ := formance.New(formance.Options{BaseURL: "http://localhost:3068"})
	dst, _ := blnk.New(blnk.Options{BaseURL: "http://localhost:5001", APIKey: os.Getenv("BLNK_API_KEY")})
	mapper, _ := mapping.New(mapping.Config{Rules: []mapping.Rule{
		{Match: "platform:fees", Indicator: "@Fees"},
		{Match: "users:*:wallet", Ledger: "Customer Wallets"},
	}})
	store, err := state.OpenFile("state.json")
	if err != nil {
		log.Fatal(err)
	}
	defer store.Close()

	m, _ := migrator.New(src, dst, migrator.Options{Ledgers: []string{"main"}, Mapper: mapper, Store: store})
	if _, err := m.Replay(ctx); err != nil {
		log.Fatal(err)
	}
	report, _ := m.Reconcile(ctx, migrator.ReconcileOptions{CheckVolumes: true})
	fmt.Println("ledgers match:", report.OK())
}

Try it without any servers: go run ./examples/quickstart.

How Formance maps to Blnk

Formance Blnk
Ledger Ledger (by name, or routed by rules)
Account × asset Balance (Blnk balances are single-currency)
world @World indicator balance (configurable)
Asset USD/2 Currency USD, precision 100
Posting Transaction with precise_amount
Multi-posting transaction Atomic bulk batch
Transaction timestamp effective_date
Metadata meta_data.formance_metadata (+ formance_* provenance keys)
Revert Replayed as a reversal, or both dropped (reverts: skip)

Project layout

Package Purpose
migrator The engine: replay, snapshot, hybrid, reconcile
mapping Account and asset mapping rules
formance Read-only Formance Ledger v2 client (bearer or OAuth2)
blnk Blnk client (ledgers, balances, bulk transactions)
state Resumable progress store (atomic JSON file with lock)
config JSON config with ${ENV} expansion
amount Big-integer amounts that survive JSON
internal/httpx Shared HTTP client: retries, backoff, rate limiting
internal/fakes In-memory Formance and Blnk fakes for tests and examples
cmd/formance2blnk The CLI

Compatibility

Built against the Formance Ledger v2 REST API and the Blnk Core API. Both evolve — run plan and a reconciliation against a staging copy first. See Compatibility for the exact endpoints used.

Contributing

Issues and pull requests are welcome — see CONTRIBUTING.md. Run make check before submitting.

License

MIT. Not affiliated with Formance or Blnk Finance.

About

Migrate a Formance Ledger (v2) into Blnk safely, resumably and verifiably. Replay, snapshot or hybrid strategies, idempotent writes and balance reconciliation. Go CLI and library with no dependencies.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages