Coder Social home page Coder Social logo

sui-go-sdk's Introduction

Sui-Go-SDK

sui-go-sdk is go language sdk for Project sui-go-sdk is project Sui SDK for Go programming language.

Notices

  • You don't need to load your sui.keystore file if you just want to send some unsigned transactions.
  • File sui.keystore in config folder is test-only. Replace and load your own sui.keystore if your need to sign transactions.
  • PRs are open to everyone and let's build useful tools for Sui community!

Features

  • Load your keystore file and sign your messages with specific address.
  • Provide methods MoveCallAndExecuteTransaction/BatchAndExecuteTransaction.
  • Customized request method SuiCall.
  • Unsigned methods can be executed without loading your keystore file.

Quick Start

Install

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

Go Version

Golang Version
>= 1.17.3

Examples

Get start

package main

import (
	"context"
	"fmt"

	"github.com/block-vision/sui-go-sdk/models"
	"github.com/block-vision/sui-go-sdk/sui"
)

func main() {
	// configure your endpoint here
	cli := sui.NewSuiClient("https://gateway.devnet.sui.io:443")
	resp, err := cli.GetRecentTransactions(context.Background(), models.GetRecentTransactionRequest{
		Count: 5,
	})
	if err != nil {
		fmt.Println(err.Error())
	}
	fmt.Println(resp)

	//If you want to request for original json response, you can use SuiCall().
	rsp, err := cli.SuiCall(context.Background(), "sui_getRecentTransactions", 5)
	if err != nil {
		fmt.Println(err.Error())
	}
	fmt.Println(rsp)

	keystoreCli, err := sui.SetAccountKeyStore("../sui.keystore.fortest")
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	fmt.Println(keystoreCli.Keys())
	fmt.Println(keystoreCli.GetKey("your-address"))
}

Send unsigned transactions

func main() {
	cli := sui.NewSuiClient("https://gateway.devnet.sui.io:443")

	keystoreCli, err := sui.SetAccountKeyStore("../sui.keystore.fortest")
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	fmt.Println(keystoreCli.Keys())
	fmt.Println(keystoreCli.GetKey("your-address"))

	resp, err := cli.MoveCall(context.Background(), models.MoveCallRequest{
		Signer:          "0x4d6f1a54e805038f44ecd3112927af147e9b9ecb",
		PackageObjectId: "0x0000000000000000000000000000000000000002",
		Module:          "devnet_nft",
		Function:        "mint",
		TypeArguments:   []interface{}{},
		Arguments:       []interface{}{"blockvision", "blockvision", "testurl"},
		Gas:             "0x14802aeff2f444c888303f8fbba6d4e8451c38f8",
		GasBudget:       1000,
	})
	
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	fmt.Println(resp)
}

Send signed transactions

func main() {
    cli := sui.NewSuiClient("https://gateway.devnet.sui.io:443")

    keystoreCli, err := sui.SetAccountKeyStore("../sui.keystore.fortest")
    if err != nil {
        fmt.Println(err.Error())
        return
	}

    fmt.Println(keystoreCli.Keys())
    fmt.Println(keystoreCli.GetKey("your-address"))

    resp, err := cli.MoveCallAndExecuteTransaction(context.Background(), models.MoveCallAndExecuteTransactionRequest{
        MoveCallRequest: models.MoveCallRequest{
            Signer:          "0x4d6f1a54e805038f44ecd3112927af147e9b9ecb",
            PackageObjectId: "0x0000000000000000000000000000000000000002",
            Module:          "devnet_nft",
            Function:        "mint",
            TypeArguments:   []interface{}{},
            Arguments:       []interface{}{"blockvision", "blockvision", "testurl"},
            Gas:             "0x14802aeff2f444c888303f8fbba6d4e8451c38f8",
            GasBudget:       1000,
        },
    })
    if err != nil {
        fmt.Println(err.Error())
        return
    }
    fmt.Println(resp)
}

Contribution

Contributions are welcomed and greatly appreciated.
Please follow the PR/issue template.
Thank you to all the people who participate in building better infrastructure!

Resources

License

Apache 2.0 license

sui-go-sdk's People

Contributors

neoandersoninmatrix avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.