> ## Documentation Index
> Fetch the complete documentation index at: https://docs.blnkfinance.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Getting Started with the Go SDK

> Learn how to work with the Blnk SDK for Go.

Welcome to the Blnk SDK for Go Developer Guide. In this guide, you'll learn how to install Blnk and work with our Blnk Go SDK. To view the open-source file, see the following: [Blnk Go SDK](https://github.com/blnkfinance/blnk-go/).

You'll also find examples of running different fintech use cases with our Go SDK.

## Prerequisites

Ensure that you have the following installed on your machine.

1. [Docker](https://www.docker.com/) and [Compose](https://docs.docker.com/compose/) for running Blnk locally on your machine.
2. [Go (v1.22 or later)](https://go.dev/doc/install) for installing and using the Blnk Go SDK.

***

## 1: Installation & Configuration

Once you're good to go with the prerequisites, you can set up your Blnk Core instance and SDK in 5 steps:

<Steps titleSize="h3">
  <Step title="Clone the Blnk repository">
    Run the following command in your terminal to clone Blnk to your local machine:

    ```bash bash theme={"system"}
    git clone https://github.com/blnkfinance/blnk && cd blnk
    ```
  </Step>

  <Step title="Set up your Blnk configuration">
    Create a `blnk.json` file in your `blnk` project folder, paste the following configuration settings, and save.

    ```json blnk.json theme={"system"}
    {
        "project_name": "Blnk",
        "data_source": {
            "dns": "postgres://postgres:password@postgres:5432/blnk?sslmode=disable"
        },
        "redis": {
            "dns": "redis:6379"
        },
        "server": {
            "domain": "blnk.io",
            "ssl": false,
            "ssl_email": "jerryenebeli@gmail.com",
            "port": "5001"
        },
        "notification": {
            "slack": {
            "webhook_url": "https://hooks.slack.com"
            }
        }
    }
    ```

    This configuration sets up the required connections to PostgreSQL and Redis, specifies your server details, and allows Slack notifications if needed.
  </Step>

  <Step title="Launch Blnk">
    Launch the Blnk Core instance with the following command:

    ```bash bash theme={"system"}
    docker compose up
    ```

    Once running, your server will be accessible at [http://localhost:5001](http://localhost:5001).
  </Step>

  <Step title="Install Blnk CLI">
    The Blnk CLI helps you to quickly test and manage your Blnk backend directly from your command line. You can also use it to perform create actions or view your data tables. To install and use the Blnk CLI, see the following in: [Installing the Blnk CLI](/blnk-cli/install).

    To confirm that the CLI has been installed, run the following command:

    ```bash bash theme={"system"}
    blnk --version
    ```
  </Step>
</Steps>

***

## 2: Install the Blnk Go SDK

In your Go project, install the Blnk Go SDK using `go get`:

```bash bash theme={"system"}
go get github.com/blnkfinance/blnk-go
```

***

## 3: Create your first ledger

A ledger is a folder for grouping balances together in your Blnk server. To learn more, see the following: [Introduction to Ledgers](/ledgers/introduction)

To create a ledger using the Go SDK:

```go Create ledger theme={"system"}
package main

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

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

func main() {
	// Initialize the Blnk client with base URL
	baseURL, _ := url.Parse("http://localhost:5001/")
	client := blnkgo.NewClient(baseURL, nil, blnkgo.WithTimeout(5*time.Second))

	// Create a ledger request
	ledgerBody := blnkgo.CreateLedgerRequest{
		Name: "Customer Savings Account",
		MetaData: map[string]interface{}{
			"project_owner": "YOUR_APP_NAME",
		},
	}

	// Create the ledger
	ledger, resp, err := client.Ledger.Create(ledgerBody)
	if err != nil {
		fmt.Printf("Error creating ledger: %v\n", err)
		return
	}

	fmt.Printf("Ledger Created: %+v\n", ledger)
	fmt.Printf("Response Status: %d\n", resp.StatusCode)
}
```

You can confirm that the ledger has been created with the Blnk CLI:

```bash bash theme={"system"}
blnk ledgers list
```

***

## 4: Create your first balance

A balance is used to represent a store of value in your Blnk server, e.g., wallet or account. To learn more, see the following: [Introduction to Balances](/balances/introduction)

To create a balance using the Go SDK:

```go Create balance theme={"system"}
// Create a balance request
balanceBody := blnkgo.CreateLedgerBalanceRequest{
	LedgerID: ledger.LedgerID,
	Currency: "USD",
	MetaData: map[string]interface{}{
		"first_name":     "Alice",
		"last_name":      "Hart",
		"account_number": "1234567890",
	},
}

// Create the balance
balance, resp, err := client.LedgerBalance.Create(balanceBody)
if err != nil {
	fmt.Printf("Error creating balance: %v\n", err)
	return
}

fmt.Printf("Balance Created: %+v\n", balance)
fmt.Printf("Response Status: %d\n", resp.StatusCode)
```

You can confirm that the balance has been created with the Blnk CLI:

```bash bash theme={"system"}
blnk balances list
```

***

## 5: Record your first transaction

Transaction records represent all financial activities (money in and money out) happening within your Blnk ledger. All transactions are immutable (cannot be modified or deleted) and idempotent (producing the same result no matter how many times an operation is performed).

To record a transaction using the Go SDK:

```go Create transaction theme={"system"}
// Create a transaction request using internal balances
// Internal balances use the "@" prefix and are automatically created if they don't exist
transactionBody := blnkgo.CreateTransactionRequest{
	// This groups the base transaction properties
	ParentTransaction: blnkgo.ParentTransaction{
		Amount:      1000,
		Reference:   "first_transaction_001",
		Currency:    "USD",
		Precision:   100,
		Source:      "@FundingPool",
		Destination: "@MyBalance",
		Description: "My first Blnk transaction",
		MetaData:    map[string]interface{}{},
	},
	// Additional transaction options are set at the CreateTransactionRequest level
	AllowOverdraft: true,
}

// Create the transaction
transaction, resp, err := client.Transaction.Create(transactionBody)
if err != nil {
	fmt.Printf("Error creating transaction: %v\n", err)
	return
}

fmt.Printf("Transaction Recorded: %+v\n", transaction)
fmt.Printf("Response Status: %d\n", resp.StatusCode)
```

You can confirm that the transaction has been created with the Blnk CLI:

```bash bash theme={"system"}
blnk transactions list
```

## 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](mailto:support@blnkfinance.com) or [join our Discord community](https://discord.gg/7WNv94zPpx).

***

<Tip>
  **Tip:** Connect to Blnk Cloud to see your Core data.

  You can view your transactions, manage identities, create custom reports, invite other team members to collaborate, and perform operations on your Core — all in one dashboard.

  [Check out Blnk Cloud →](https://www.blnkfinance.com/products/cloud)
</Tip>

## Issue reporting

If you encounter any issues while installing or using this SDK, please [report them on Github](https://github.com/blnkfinance/blnk/issues).
