Mainly

Go

Install and make your first Mainly request with the Go SDK.

The official Go SDK is published as the module github.com/mainly-live/mainly-go.

Install

From your Go module, run:

go get github.com/mainly-live/mainly-go@latest

Make a request

Create one client and reuse it across requests:

package main

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

	mainlyclient "github.com/mainly-live/mainly-go/client"
	"github.com/mainly-live/mainly-go/option"
	"github.com/mainly-live/mainly-go/solana"
)

func main() {
	client := mainlyclient.NewClient(
		option.WithToken(os.Getenv("MAINLY_API_KEY")),
	)

	balance, err := client.Solana.Wallets.GetBalance(
		context.Background(),
		&solana.GetBalanceWalletsRequest{
			Address: "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM",
		},
	)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Balance: %f SOL\n", balance.Sol)
}

option.WithToken sends your key as an Authorization: Bearer header.

Choose a network

Resources are grouped by chain and network on the client:

client.Solana
client.SolanaDevnet
client.Ethereum
client.EthereumSepolia

For example, change client.Solana to client.SolanaDevnet to make the same request against Solana devnet.

Handle errors and timeouts

Every call returns a response and an error. Use the standard errors.As API to inspect structured API errors, and a context deadline to bound a request:

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

balance, err := client.Solana.Wallets.GetBalance(ctx, request)

The SDK also retries retryable failures with exponential backoff. Configure the retry limit with option.WithMaxAttempts when you create the client or when you make an individual request.

Next, browse the API reference or see the complete Go SDK source.

On this page