sdkgo

package module
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: May 20, 2025 License: Apache-2.0 Imports: 3 Imported by: 6

README

English | 简体中文

CESS Network SDK for Go

GitHub license Go Reference build Go Report Card

CESS Network SDK for Go allows you to access the CESS blockchain network, such as querying block data, transactions, and calling RPC methods. You don't need to deal with API related tasks such as signing and building requests to access the CESS blockchain network. It also allows you to access the storage network, such as uploading or downloading data directly from storage nodes, as well as implementations of file chunking, encryption, and redundancy.

Bulletin

  • Test Network RPC Endpoint
wss://testnet-rpc.cess.network/ws/
  • Test Network Faucet
https://www.cess.network/faucet.html

Requirements

Install a Go environment newer than 1.22.x.

Installation

Use go get to install SDK:

go get -u "github.com/CESSProject/cess-go-sdk"

Quick Use

Quickly create your SDK client:

cli, err := sdkgo.New(
    context.Background(),
    sdkgo.ConnectRpcAddrs("wss://testnet-rpc.cess.network/ws/"),
)

Testing

To run test:

make check

Documentation

Issues

If you find any system errors or you have better suggestions, please submit an issue or PR, or join the CESS discord to communicate with us.

License

Licensed under Apache 2.0

Documentation

Index

Constants

View Source
const DefaultName = "cess-sdk-go"
View Source
const Version = "0.7.0"

SDK Version

Variables

View Source
var DefaultRpcAddrs = func(cfg *Config) error {
	rpcAddrs := []string{
		"wss://testnet-rpc.cess.network/ws/",
	}
	return cfg.Apply(ConnectRpcAddrs(rpcAddrs))
}

DefaultRpcAddrs configures the default rpc address

View Source
var DefaultSDKName = func(cfg *Config) error {
	return cfg.Apply(Name(DefaultName))
}

DefaultTimeout configures the default transaction waiting timeout

View Source
var DefaultTimeout = func(cfg *Config) error {
	return cfg.Apply(TransactionTimeout(time.Second * 18))
}

DefaultTimeout configures the default transaction waiting timeout

Functions

func New

func New(ctx context.Context, opts ...Option) (chain.Chainer, error)

NewDefault constructs a new SDK client using the given options and default options.

If no rpc endpoint are provided, use the default: “wss://testnet-rpc.cess.network/ws/”

If no transaction timeout are provided, use the default timeout: 18s

If no name are provided, use the default name: cess-sdk-go

func NewWithoutDefaults

func NewWithoutDefaults(ctx context.Context, opts ...Option) (chain.Chainer, error)

New constructs a new sdk client with the given options.

If no rpc endpoint are provided, the CESS blockchain network cannot be accessed.

If no account mnemonic are provided, block transactions cannot be conducted.

Types

type Config

type Config struct {
	Rpc      []string
	Mnemonic string
	Name     string
	Timeout  time.Duration
}

Config describes a set of settings for a client

func (*Config) Apply added in v0.6.0

func (cfg *Config) Apply(opts ...Option) error

Apply applies the given options to the config, returning the first error encountered (if any).

func (*Config) NewSDK added in v0.6.0

func (cfg *Config) NewSDK(ctx context.Context) (chain.Chainer, error)

NewSDK constructs a new client from the Config.

This function consumes the config. Do not reuse it (really!).

type Option

type Option func(cfg *Config) error

Option is a client config option that can be given to the client constructor

var FallbackDefaults Option = func(cfg *Config) error {
	for _, def := range defaults {
		if !def.fallback(cfg) {
			continue
		}
		if err := cfg.Apply(def.opt); err != nil {
			return err
		}
	}
	return nil
}

FallbackDefaults Default options are used if and only if no other relevant options apply.

func ConnectRpcAddrs

func ConnectRpcAddrs(s []string) Option

ConnectRpcAddrs configuration rpc address

func Mnemonic

func Mnemonic(mnemonic string) Option

Mnemonic configures the mnemonic of the signature account

func Name added in v0.4.1

func Name(name string) Option

Name configuration sdk name

func TransactionTimeout

func TransactionTimeout(timeout time.Duration) Option

TransactionTimeout configures the waiting timeout for a transaction

Jump to

Keyboard shortcuts

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