Skip to main content
Version: 1.x

Go SDK API Reference

The Go SDK package is github.com/layer-3/nitrolite/sdk/go. It wraps Nitronode v1 RPC methods and ChannelHub settlement helpers in typed Go methods.

App-Builder Methods​

These are the methods most builders use in normal applications.

Channel State​

client.Deposit(ctx, blockchainID, asset, amount) // (*core.State, error)
client.Withdraw(ctx, blockchainID, asset, amount) // (*core.State, error)
client.Transfer(ctx, recipientWallet, asset, amount) // (*core.State, error)
client.CloseHomeChannel(ctx, asset) // (*core.State, error)
client.Acknowledge(ctx, asset) // (*core.State, error)

Use Checkpoint when the latest prepared state needs on-chain settlement.

Settlement​

client.Checkpoint(ctx, asset) // (string, error)
client.Challenge(ctx, state) // (string, error)
client.ApproveToken(ctx, chainID, asset, amount) // (string, error)
client.GetOnChainBalance(ctx, chainID, asset, wallet) // (decimal.Decimal, error)

Checkpoint routes by transition type and channel status:

Latest stateEffect
Void channel plus deposit stateCreates the channel and locks funds.
Deposit or withdrawal stateCheckpoints and applies the fund movement.
Finalize stateCloses the channel.

Node and Asset Discovery​

client.Ping(ctx)
client.GetConfig(ctx)
client.GetBlockchains(ctx)
client.GetAssets(ctx, &blockchainID)
client.SetHomeBlockchain(asset, chainID)

User and Channel Queries​

client.GetBalances(ctx, wallet)
client.GetTransactions(ctx, wallet, opts)
client.GetHomeChannel(ctx, wallet, asset)
client.GetEscrowChannel(ctx, escrowChannelID)
client.GetLatestState(ctx, wallet, asset, onlySigned)

GetEscrowChannel is a query helper. Escrow operation guides are not public app-builder docs yet.

App Registry and Sessions​

apps, meta, err := client.GetApps(ctx, &sdk.GetAppsOptions{
AppID: &appID,
OwnerWallet: &wallet,
})

err := client.RegisterApp(ctx, "my-app", `{"name":"My App"}`, false)
sessions, meta, err := client.GetAppSessions(ctx, opts)
def, err := client.GetAppDefinition(ctx, appSessionID)
sessionID, version, status, err := client.CreateAppSession(ctx, def, data, sigs)
nodeSig, err := client.SubmitAppSessionDeposit(ctx, update, sigs, asset, amount)
err := client.SubmitAppState(ctx, update, sigs)
batchID, err := client.RebalanceAppSessions(ctx, signedUpdates)

Apps are responsible for collecting quorum signatures before calling CreateAppSession, SubmitAppSessionDeposit, or SubmitAppState.

Session Keys​

App Sessions​

state := app.AppSessionKeyStateV1{
UserAddress: client.GetUserAddress(),
SessionKey: "0xSessionKey...",
Version: 1,
ApplicationIDs: []string{"app1"},
AppSessionIDs: []string{},
ExpiresAt: time.Now().Add(24 * time.Hour),
}

sig, err := client.SignSessionKeyState(state)
state.UserSig = sig
err = client.SubmitAppSessionKeyState(ctx, state)

states, err := client.GetLastAppKeyStates(ctx, userAddress, nil)

Channels​

state := core.ChannelSessionKeyStateV1{
UserAddress: client.GetUserAddress(),
SessionKey: "0xSessionKey...",
Version: 1,
Assets: []string{"yellow"},
ExpiresAt: time.Now().Add(24 * time.Hour),
}

sig, err := client.SignChannelSessionKeyState(state)
state.UserSig = sig
err = client.SubmitChannelSessionKeyState(ctx, state)

states, err := client.GetLastChannelKeyStates(ctx, userAddress, nil)

Utilities​

client.Close()
client.WaitCh()
client.SignState(state)
client.GetUserAddress()

Common Types​

core.State
core.Channel
core.Transition
core.Transaction
core.Asset
core.Blockchain
core.ChannelSessionKeyStateV1

app.AppV1
app.AppInfoV1
app.AppSessionInfoV1
app.AppDefinitionV1
app.AppStateUpdateV1
app.AppSessionKeyStateV1