Initialize SDK

When you are using Go SDK, you need to initialize a SDK instance, and modify the default config according the needs.

You need to provide some configuration information:

parameterdescriptionmethod

RPC address

CESS chain rpc address

cess.ConnectRpcAddrs

Mnemonic

CESS wallet mnemonic phrase, if ignored, no transaction can be made.

cess.Mnemonic

TransactionTimeout

Transaction timeout

cess.TransactionTimeout

Name

SDK name

cess.Name

Minimum configuration sdk client

package main

import (
	"context"
	"fmt"

	cess "github.com/CESSProject/cess-go-sdk"
)

var RPC_ADDRS = []string{
	//test net
	"wss://testnet-rpc0.cess.cloud/ws/",
	"wss://testnet-rpc1.cess.cloud/ws/",
	"wss://testnet-rpc2.cess.cloud/ws/",
}

func main() {
	sdk, err := cess.New(
		context.Background(),
		cess.ConnectRpcAddrs(RPC_ADDRS),
	)
	if err != nil {
		panic(err)
	}
	fmt.Println(sdk.SysVersion())
}

Fully configured sdk client

package main

import (
	"context"
	"fmt"
	"time"

	cess "github.com/CESSProject/cess-go-sdk"
)

// Substrate well-known mnemonic:
//
//	https://github.com/substrate-developer-hub/substrate-developer-hub.github.io/issues/613
var MY_MNEMONIC = "bottom drive obey lake curtain smoke basket hold race lonely fit walk"

var RPC_ADDRS = []string{
	"wss://testnet-rpc0.cess.cloud/ws/",
	"wss://testnet-rpc1.cess.cloud/ws/",
	"wss://testnet-rpc2.cess.cloud/ws/",
}

func main() {
	sdk, err := cess.New(
		context.Background(),
		cess.ConnectRpcAddrs(RPC_ADDRS),
		cess.Mnemonic(MY_MNEMONIC),
		cess.TransactionTimeout(time.Second*10),
		cess.Name("my-sdk"),
	)
	if err != nil {
		panic(err)
	}
	fmt.Println(sdk.SysVersion())
}

Last updated