Introduction to the Go SDK
Getting Started
The ULedger SDK is a framework for building blockchain applications. Written in Go, this SDK is used to develop applications within the ULedger ecosystem and serves as a powerful tool for interacting with a ULedger blockchain network. It lets you create and manage wallets as well as sign, submit, and query transactions; blocks and wallet activity.
By integrating the SDK into your Go applications, you tap into ULedger’s cryptographic and privacy features. This includes strong encryption that support post-quantum, encryption, zero knowledge proof and Cross-Merkleization.
Preparing a Go development environment
This guide sets up a complete Go development environment so you can start building with the ULedger Go SDK, and by the end of it you will have Go installed, a project initialized with the SDK and a program that connects to a node.
Prerequisites
You need a computer running macOS, Linux or Windows, basic familiarity with the command line and internet access to download dependencies. The SDK requires Go 1.24.1 or later. No prior Go experience is required, yet basic programming knowledge helps.
Step 1: Install Go
Go ships as a single binary. Download the latest stable version for your operating system from go.dev/dl and install it.
- macOS and Linux: run the installer, or extract the archive and follow the instructions on the download page.
- Windows: run the
.msiinstaller and follow the setup wizard.
To verify the installation, open a terminal and run:
go version
You should see output similar to the following, although the version and platform will differ on your machine:
go version go1.24.1 darwin/arm64
If you see a version number, Go is installed.
Step 2: Understand the Go workspace
Modern Go projects use Go modules, so you do not need to place your code in a special GOPATH. Each project lives in its own folder and manages its dependencies on its own.
Step 3: Create a new Go project
Create a directory for your application and initialize a Go module in it:
mkdir my-uledger-blockchain-app
cd my-uledger-blockchain-app
go mod init github.com/your-org/my-uledger-blockchain-app
The last command creates a go.mod file, which tracks all the dependencies of your project.
Step 4: Install the SDK
Use go get to add the SDK to your project:
go get github.com/ULedgerInc/go-sdk
Go downloads the SDK, resolves its dependencies and updates your go.mod and go.sum files.
Step 5: Create your first application
Create a main.go file and add the following code, which loads a wallet from a file or creates one on the first run, and then opens a transaction session with a node:
:::warning Replace the example node URL
The example uses https://your-node-url as a placeholder. Replace it with the URL of the node you are connecting to, for example a node on your local network. Use the base URL of the node, with no trailing slash and no path.
:::
package main
import (
"errors"
"fmt"
"os"
"github.com/ULedgerInc/go-sdk/pkg/crypto"
"github.com/ULedgerInc/go-sdk/pkg/transaction"
"github.com/ULedgerInc/go-sdk/pkg/wallet"
)
const (
nodeURL = "https://your-node-url"
walletFilePath = "my-wallet.ukey"
)
func loadOrCreateWallet() (*wallet.UL_Wallet, error) {
// Try to load an existing wallet first
loaded, err := wallet.LoadFromFile(walletFilePath, "")
if err == nil {
fmt.Println("Wallet loaded from", walletFilePath)
return &loaded, nil
}
if !errors.Is(err, os.ErrNotExist) {
return nil, fmt.Errorf("load wallet: %w", err)
}
// Otherwise create a new one
w, mnemonic, err := wallet.GenerateNewWallet(
"", // passphrase (optional)
crypto.KeyTypeSecp256k1, // key type
"", // parent (empty for a root wallet)
map[string]wallet.UL_AuthPermission{}, // auth groups
wallet.DefaultEntropy, // defaults to Entropy256
)
if err != nil {
return nil, fmt.Errorf("generate wallet: %w", err)
}
// Saving the private key to a file is fine for a first run, not for production
if err := w.SaveToFile(walletFilePath, "", true); err != nil {
return nil, fmt.Errorf("save wallet: %w", err)
}
fmt.Println("New wallet created and saved to", walletFilePath)
fmt.Println("Mnemonic (store it safely):", mnemonic)
return &w, nil
}
func main() {
fmt.Println("ULedger development environment with the Go SDK")
w, err := loadOrCreateWallet()
if err != nil {
fmt.Printf("Error loading or creating the wallet: %v\n", err)
return
}
fmt.Println("Wallet address:", w.Address)
// NewUL_TransactionSession calls the node to read its health and blockchains
if _, err := transaction.NewUL_TransactionSession(nodeURL, *w); err != nil {
fmt.Printf("Error creating the transaction session: %v\n", err)
return
}
fmt.Println("Transaction session created and connected to the node")
}
Then tidy up the dependencies:
go mod tidy
Never hardcode sensitive data in production, such as node URLs or wallet keys, and read them from environment variables instead.
Step 6: Run the application
Run the program:
go run main.go
On the first run it creates the wallet and prints its mnemonic and address, then it connects to the node, so you should see output like this:
ULedger development environment with the Go SDK
New wallet created and saved to my-wallet.ukey
Mnemonic (store it safely): ...
Wallet address: ...
Transaction session created and connected to the node
On later runs it loads my-wallet.ukey and skips the creation step.
Recommended tools
Visual Studio Code with the official Go extension gives you formatting, linting and debugging out of the box, while golangci-lint is a useful optional addition for stricter checks.
Common issues
go: command not found
Make sure Go is on your system PATH, then open a new terminal and run go version again.
Dependency errors
Run go mod tidy to resolve missing or outdated dependencies, and then run the program again.
The transaction session fails to connect
The session reads the node's health and blockchains when it is created, so check that the node URL is correct and reachable from your machine.
Next steps
Continue with Create a Wallet and then Register & Create Transactions.