Sui Go SDK: Build and Interact with Sui Blockchain Using Golang

ยท

The Sui Go SDK is a powerful, developer-friendly software development kit designed to streamline interactions with the Sui blockchain using the Go programming language. Developed and maintained by the SuiVision team, this open-source SDK provides comprehensive access to Suiโ€™s RPC methods while introducing enhanced utilities that simplify integration for blockchain developers. Whether you're building decentralized applications (dApps), backend services, or wallet integrations, the Sui Go SDK offers the tools you need to interact efficiently with the Sui network.

This guide walks you through the core features, setup process, practical code examples, and advanced capabilities of the SDKโ€”all while aligning with modern development best practices and blockchain standards.


Key Features of the Sui Go SDK

The Sui Go SDK stands out for its robust functionality and ease of use. It supports essential modules such as Object management, Coin operations, Event handling, Transaction processing, and System Data queries. Below are some of its standout capabilities:

These features make the Sui Go SDK an excellent choice for Go developers entering the Web3 space or scaling existing blockchain solutions on Sui.

๐Ÿ‘‰ Discover powerful blockchain tools to enhance your development workflow.


Getting Started with the Sui Go SDK

Installation

To begin using the SDK in your Go project, install it using go get:

go get github.com/block-vision/sui-go-sdk

Ensure your environment is running a compatible version of Go. The SDK is optimized for Go 1.19+, though it generally works with newer versions without issues.


Connecting to the Sui Network

Use the NewSuiClient function to connect to either the Sui TestNet or MainNet by providing a valid RPC endpoint. For convenience, BlockVision offers fast and free endpoints:

Here's how to initialize a client:

package main

import (
    "context"
    "fmt"
    "github.com/block-vision/sui-go-sdk/sui"
)

func main() {
    cli := sui.NewSuiClient("https://sui-testnet-endpoint.blockvision.org")
    fmt.Println("Connected to Sui TestNet")
}

This lightweight setup allows immediate interaction with the blockchain for both reading and writing data.


Practical Examples: Reading and Writing on Sui

Requesting Test Tokens from the Faucet

During development on DevNet or TestNet, you can obtain test SUI tokens from a faucet:

func RequestDevNetSuiFromFaucet() {
    faucetHost, err := sui.GetFaucetHost(constant.SuiDevnet)
    if err != nil {
        fmt.Println("GetFaucetHost err:", err)
        return
    }
    recipient := "0xaf9f4d20c205f26051a7e1758601c4c47a9f99df3f9823f70926c17c80882d36"
    header := map[string]string{}
    err = sui.RequestSuiFromFaucet(faucetHost, recipient, header)
    if err != nil {
        fmt.Println(err.Error())
        return
    }
    fmt.Println("Request DevNet Sui From Faucet success")
}

This feature accelerates testing cycles by eliminating manual token acquisition.


Writing Transaction Blocks

Transfer an Object

Move ownership of a specific object between addresses:

rsp, err := cli.TransferObject(ctx, models.TransferObjectRequest{
    Signer:     signerAccount.Address,
    ObjectId:   "0x99b5...",
    Gas:        &gasObj,
    GasBudget:  "100000000",
    Recipient:  "0xaf9f...",
})

After preparing the transaction metadata, sign and execute it:

rsp2, err := cli.SignAndExecuteTransactionBlock(ctx, models.SignAndExecuteTransactionBlockRequest{
    TxnMetaData: rsp,
    PriKey:      priKey,
    Options: models.SuiTransactionBlockOptions{
        ShowEffects: true,
    },
    RequestType: "WaitForLocalExecution",
})

Transfer SUI Tokens

Send native SUI coins securely:

rsp, err := cli.TransferSui(ctx, models.TransferSuiRequest{
    Signer:       signerAccount.Address,
    SuiObjectId:  "0xc699...",
    GasBudget:    "100000000",
    Recipient:    "0xb7f9...",
    Amount:       "1",
})

Execute a Move Call

Interact directly with Move smart contracts:

rsp, err := cli.MoveCall(ctx, models.MoveCallRequest{
    Signer:           signerAccount.Address,
    PackageObjectId:  "0x7d58...",
    Module:           "auction",
    Function:         "start_an_auction",
    Arguments:        []interface{}{"arg1", "arg2"},
    GasBudget:        "100000000",
})

Merge Coins

Combine multiple coin objects into one:

rsp, err := cli.MergeCoins(ctx, models.MergeCoinsRequest{
    Signer:       signerAccount.Address,
    PrimaryCoin:  "0x180f...",
    CoinToMerge:  "0x3b46...",
    GasBudget:    "100000000",
})

Each operation returns detailed response data for verification and logging.


Reading Data from the Sui Blockchain

Fetch Balance Information

Retrieve all coin balances for a given address:

rsp, err := cli.SuiXGetAllBalance(ctx, models.SuiXGetAllBalanceRequest{
    Owner: "0xb7f9...",
})

Get Coin Metadata

Obtain metadata about custom coin types:

rsp, err := cli.SuiXGetCoinMetadata(ctx, models.SuiXGetCoinMetadataRequest{
    CoinType: "0xf7a0...::busd::BUSD",
})

Query Owned Objects and Transactions

List all objects owned by an address:

rsp, err := cli.SuiXGetOwnedObjects(ctx, models.SuiXGetOwnedObjectsRequest{
    Address: "0xb7f9...",
    Limit:   5,
})

Fetch transaction details using digest IDs:

rsp, err := cli.SuiGetTransactionBlock(ctx, models.SuiGetTransactionBlockRequest{
    Digest: "CeVpDXKKU3Gs89efej9pKiYYQyTzifE2BDxWwquUaUht",
})

You can also batch-fetch multiple transactions using SuiMultiGetTransactionBlocks.


Real-Time Data with WebSocket Subscriptions

Stay updated in real time by subscribing to event and transaction streams.

Subscribe to Events

Listen for live events emitted by smart contracts:

err := cli.SubscribeEvent(ctx, models.SuiXSubscribeEventsRequest{
    SuiEventFilter: map[string]interface{}{"All": []string{}},
}, receiveMsgCh)

Subscribe to Transactions

Monitor transaction effects from specific senders:

err := cli.SubscribeTransaction(ctx, models.SuiXSubscribeTransactionsRequest{
    TransactionFilter: models.TransactionFilterByFromAddress{
        FromAddress: "0x0000...",
    },
}, receiveMsgCh)

These capabilities are crucial for building responsive dashboards, monitoring tools, or reactive backend systems.


Frequently Asked Questions (FAQ)

Q: Is the Sui Go SDK open source?
A: Yes, the SDK is fully open source and licensed under Apache 2.0. You can view and contribute to the code on GitHub.

Q: Can I use this SDK in production environments?
A: Absolutely. The SDK is stable and widely used in dApp development, especially when paired with reliable RPC endpoints.

Q: Does it support both TestNet and MainNet?
A: Yes, you can switch between networks by changing the RPC URL during client initialization.

Q: How do I handle private keys securely?
A: Always store mnemonics and private keys in secure environments (e.g., environment variables or hardware wallets). Never hardcode them in source files.

Q: Where can I find more examples?
A: Comprehensive examples are available in the official GitHub repository.

Q: What if I need custom RPC calls not covered by built-in methods?
A: Use the flexible SuiCall method to send any valid JSON-RPC request directly to the Sui node.

๐Ÿ‘‰ Explore next-gen blockchain development platforms to boost your projectโ€™s potential.


Core Keywords for SEO Optimization

These keywords have been naturally integrated throughout the content to improve search visibility while maintaining readability.


Final Thoughts

The Sui Go SDK empowers Golang developers to seamlessly integrate with the high-performance Sui blockchain. With intuitive APIs for reading data, submitting transactions, and subscribing to real-time events, it lowers the barrier to entry for Web3 development without sacrificing power or flexibility.

Whether you're building infrastructure tools, financial applications, or NFT marketplaces, this SDK provides a solid foundation for scalable and efficient blockchain interaction.

๐Ÿ‘‰ Accelerate your blockchain journey with advanced developer resources.