Skip to content

Go SDK Setup

The Go SDK is published as the module github.com/phantasma-io/phantasma-sdk-go.

Requirements

ItemRequirement
Go1.25 or newer
Toolchain used by the source repogo1.26.2
Current public tagv0.18.1

Install the module:

go get github.com/phantasma-io/phantasma-sdk-go

Imports

Use the packages that own the API area:

import (
    "github.com/phantasma-io/phantasma-sdk-go/pkg/carbon"
    "github.com/phantasma-io/phantasma-sdk-go/pkg/cryptography"
    "github.com/phantasma-io/phantasma-sdk-go/pkg/rpc"
    scriptbuilder "github.com/phantasma-io/phantasma-sdk-go/pkg/vm/script_builder"
)

Lower-level packages such as pkg/io, pkg/jsonrpc, pkg/domain, and pkg/vm are public for protocol tooling and migration work. Application code should prefer the higher-level packages unless it needs direct wire-format control.

RPC Client

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

client := rpc.NewRPC("http://localhost:5172/rpc")
// client := rpc.NewRPCMainnet()
// client := rpc.NewRPCTestnet()

All typed RPC methods take context.Context as their first argument. Use contexts to enforce request deadlines and cancellation.

Source Layout

PathContents
pkg/rpcJSON-RPC client and typed method wrappers.
pkg/rpc/responseResult models returned by RPC wrappers.
pkg/carbonCarbon serialization, transaction messages, token builders, fee options, and result parsers.
pkg/cryptographyAddress, WIF, Ed25519 key, signature, and hash types.
pkg/vm/script_builderVM script builder and high-level script helpers.
pkg/blockchainScript transaction type and transaction state helpers.