go-sui-sdk

module
v0.1.11-sip58 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2026 License: Apache-2.0

README

go-sui-sdk

Sui Golang SDK

Documentation (master) License

The Sui Golang SDK for ComingChat. We welcome other developers to participate in the development and testing of sui-sdk.

Install

go get github.com/coming-chat/go-sui/v2

Backends: JSON-RPC (v1) and gRPC (v2)

Sui is retiring its public JSON-RPC endpoints in favor of the gRPC API (sui.rpc.v2). This SDK supports both behind one interface; select the backend with a flag:

import "github.com/utila-io/go-sui-sdk/suiclient"

// Default: JSON-RPC (unchanged behavior), endpoint is an https URL
cli, err := suiclient.New("https://fullnode.mainnet.sui.io")

// Opt into gRPC: endpoint is "grpc://host[:port]" or "host[:port]" (port
// defaults to 443), always TLS — http:// and https:// are rejected
cli, err := suiclient.New("fullnode.mainnet.sui.io:443", suiclient.WithBackend(suiclient.BackendGRPC))
defer cli.Close()

// Plaintext gRPC (local node, internal bridge) is an explicit opt-in
cli, err := suiclient.New("localhost:9000",
	suiclient.WithBackend(suiclient.BackendGRPC), suiclient.WithInsecure())

// Provider auth headers (works on both backends; repeatable)
cli, err := suiclient.New(endpoint,
	suiclient.WithBackend(suiclient.BackendGRPC), suiclient.WithHeader("x-token", token))

bal, err := cli.GetBalance(ctx, owner, "") // same interface either way

The suiclient.SuiClient interface contains only methods both backends fully support: balances & coins (including SIP-58 address balances and accumulatorEvents on effects), objects, transaction reads/execution/simulation, and checkpoints.

Not on the interface (JSON-RPC concrete client.Client only): the unsafe_* server-side transaction builders, faucet, staking/APY reads, and arbitrary queryTransactionBlocks/queryEvents filters — build transactions locally with sui_types.ProgrammableTransactionBuilder instead, and enumerate checkpoint transactions with GetCheckpointTransactions.

The gRPC bindings are generated from the MystenLabs/sui-apis protos, pinned via the third_party/sui-apis git submodule. The generated code is committed, so consumers installing via go get need nothing extra; the submodule is only needed to regenerate (git submodule update --init, then make proto, or make proto-update after bumping SUI_APIS_REF to move the pin). Note that grpc-go raises the module's minimum Go version to 1.26.

Usage

Account
import "github.com/coming-chat/go-sui/account"

// Import account with mnemonic
acc, err := account.NewAccountWithMnemonic(mnemonic)

// Import account with private key
privateKey, err := hex.DecodeString("4ec5a9eefc0bb86027a6f3ba718793c813505acc25ed09447caf6a069accdd4b")
acc, err := account.NewAccount(privateKey)

// Get private key, public key, address
fmt.Printf("privateKey = %x\n", acc.PrivateKey[:32])
fmt.Printf(" publicKey = %x\n", acc.PublicKey)
fmt.Printf("   address = %v\n", acc.Address)

// Sign data
signedData := acc.Sign(data)
JSON RPC Client

All data interactions on the Sui chain are implemented through the rpc client.

import "github.com/coming-chat/go-sui/client"
import "github.com/coming-chat/go-sui/types"

cli, err := client.Dial(rpcUrl)

// call JSON RPC
responseObject := uint64(0) // if response is a uint64
err := cli.CallContext(ctx, &responseObject, funcName, params...)

// e.g. call get transaction
digest, err := types.NewBase64Data("/KXvTwNRHKKzAB+/Dz1O64LjVbISgIW4VUCmuuPyEfU=")
resp := types.TransactionResponse{}
err := cli.CallContext(ctx, &resp, "sui_getTransaction", digest)
print("transaction status = ", resp.Effects.Status)
print("transaction timestamp = ", resp.TimestampMs)

// And you can call some predefined methods
digest, err := types.NewBase64Data("/KXvTwNRHKKzAB+/Dz1O64LjVbISgIW4VUCmuuPyEfU=")
resp, err := cli.GetTransaction(ctx, digest)
print("transaction status = ", resp.Effects.Status)
print("transaction timestamp = ", resp.TimestampMs)

We currently have some rpc methods built-in, see here

Build Transaction & Sign ( Transfer Sui )
import "github.com/coming-chat/go-sui/client"
import "github.com/coming-chat/go-sui/types"
import "github.com/coming-chat/go-sui/account"

acc, err := account.NewAccountWithMnemonic(mnemonic)
signer, _ := types.NewAddressFromHex(acc.Address)

recipient, err := types.NewAddressFromHex("0x12345678.......")
suiObjectId, err := types.NewHexData("0x36d3176a796e167ffcbd823c94718e7db56b955f")
transferAmount := uint64(10000)
maxGasTransfer := 100

cli, err := client.Dial(rpcUrl)
txnBytes, err := cli.TransferSui(ctx, *signer, *recipient, suiObjectId, transferAmount, maxGasTransfer)

// Sign
signedTxn := txnBytes.SignWith(acc.PrivateKey)

Send Signed Transaction
txnResponse, err := cli.ExecuteTransaction(ctx, signedTxn)

print("transaction digest = ", txnResponse.Certificate.TransactionDigest)
print("transaction status = ", txnResponse.Effects.Status)
print("transaction gasFee = ", txnResponse.Effects.GasFee())

Directories

Path Synopsis
Package clientv2 is the sui.rpc.v2 gRPC backend of suiclient.SuiClient.
Package clientv2 is the sui.rpc.v2 gRPC backend of suiclient.SuiClient.
internal/genmock/pb/sui/rpc/v2
Package mock_rpcv2 is a generated GoMock package.
Package mock_rpcv2 is a generated GoMock package.
internal/pb/sui/rpc/v2
Package rpcv2 holds the generated sui.rpc.v2 protobuf and gRPC bindings, plus the hand-written conversions from those wire messages to the SDK's internal types (the types, sui_types and lib packages).
Package rpcv2 holds the generated sui.rpc.v2 protobuf and gRPC bindings, plus the hand-written conversions from those wire messages to the SDK's internal types (the types, sui_types and lib packages).
genmock
suiclient
Package mock_suiclient is a generated GoMock package.
Package mock_suiclient is a generated GoMock package.
Package suiclient provides a backend-neutral Sui client: the same SuiClient interface served by JSON-RPC (the default) or the sui.rpc.v2 gRPC backend.
Package suiclient provides a backend-neutral Sui client: the same SuiClient interface served by JSON-RPC (the default) or the sui.rpc.v2 gRPC backend.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL