gosdk

package
v2.16.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: BSD-2-Clause Imports: 30 Imported by: 1

README

Nibiru Go SDK - NibiruChain/nibiru/gosdk

A Golang client for interacting with the Nibiru blockchain.

The Nibiru Go SDK extends the core blockchain logic with extensions to build external clients for the Nibiru blockchain and easily access its query and transaction types.


Dev Notes - Nibiru Go SDK

Usage Guides & Dev Ex
  • Create a quick start guide: Connecting to Nibiru, querying Nibiru, sending transactions on Nibiru
  • Write usage examples
    • Creating an account and keyring
    • Querying balances
    • Broadcasting txs to transfer funds
    • Querying Wasm smart contracts
    • Broadcasting txs to transfer funds
  • impl Tendermint RPC client
  • refactor: DRY improvements on the QueryClient initialization
  • ci: Add go tests to CI
  • ci: Add code coverage to CI
  • ci: Add linting to CI
Feature Backlog
  • impl wallet abstraction for the keyring
  • epic: storing transaction history storage
Question Brain-dump

Q: Should gosdk run as a binary?

No, or at least, not initially. Since the software required to operate a full node has more cumbersome dependencies like RocksDB that involve C-Go and complex build steps, we may benefit from splitting "start" command from the bulk of the subcommands available on the Nibiru CLI. This would make it much easier to have a command line tool that builds on Linux, Windows, Mac.

Q: Should there be a way to run queries with JSON-RPC 2 instead of GRPC?

We implemented this in python without too much trouble, and it's not taxing to maintain. If we're going to prioritize adding APIs for the CometBFT JSON-RPC methods, it should be in the Nibiru TypeScript SDK first.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NETWORK_INFO_DEFAULT = NetworkInfo{
		EvmChainID:        appconst.ETH_CHAIN_ID_LOCALNET_0,
		EvmChainIDHex:     "0x1B0A",
		EvmRpc:            "http://127.0.0.1:8545",
		EvmRpcArchive:     "",
		EvmWebsocket:      "http://127.0.0.1:8546",
		CmtChainID:        "nibiru-localnet-0",
		GrpcEndpoint:      "localhost:9090",
		LcdEndpoint:       "http://localhost:1317",
		TmRpcEndpoint:     "http://localhost:26657",
		WebsocketEndpoint: "ws://localhost:26657/websocket",
	}
	NETWORK_INFO_NIBIRU_MAINNET = NetworkInfo{
		EvmChainID:        appconst.ETH_CHAIN_ID_MAINNET,
		EvmChainIDHex:     "0x1AF4",
		EvmRpc:            "https://evm-rpc.nibiru.fi:443",
		EvmRpcArchive:     "https://evm-rpc.archive.nibiru.fi:443",
		EvmWebsocket:      "wss://evm-rpc-ws.nibiru.fi",
		CmtChainID:        appconst.SDK_CHAIN_ID_MAINNET,
		GrpcEndpoint:      "grpc.nibiru.fi:443",
		TmRpcEndpoint:     "https://rpc.nibiru.fi:443",
		WebsocketEndpoint: "",
	}
)

Functions

func AddSignerToKeyringSecp256k1

func AddSignerToKeyringSecp256k1(
	kring keyring.Keyring, mnemonic string, keyName string,
) (sdk.AccAddress, error)

func BroadcastMsgs

func BroadcastMsgs(
	args BroadcastArgs,
	from sdk.AccAddress,
	msgs ...sdk.Msg,
) (*sdk.TxResponse, error)

func BroadcastMsgsWithSeq

func BroadcastMsgsWithSeq(
	args BroadcastArgs,
	from sdk.AccAddress,
	seq uint64,
	msgs ...sdk.Msg,
) (*sdk.TxResponse, error)

func EnsureNibiruPrefix

func EnsureNibiruPrefix()

func GetGRPCConnection

func GetGRPCConnection(
	grpcUrl string, grpcInsecure bool, timeoutSeconds int64,
) (*grpc.ClientConn, error)

GetGRPCConnection establishes a connection to a gRPC server using either secure (TLS) or insecure credentials. The function blocks until the connection is established or the specified timeout is reached.

func NewKeyring

func NewKeyring() keyring.Keyring

NewKeyring: Creates an empty, in-memory keyring

func NewRPCClient

func NewRPCClient(rpcEndpt string, websocket string) (*cmtrpchttp.HTTP, error)

NewRPCClient: A remote Comet-BFT RPC client. An error is returned on invalid remote. The function panics when remote is nil.

Args:

  • rpcEndpt: endpoint in the form <protocol>://<host>:<port>
  • websocket: websocket path (which always seems to be "/websocket")

func TxHashBytesToHex

func TxHashBytesToHex(txHashBz []byte) (txHashHex string)

func TxHashHexToBytes

func TxHashHexToBytes(txHashHex string) ([]byte, error)

Types

type AccountNumbers

type AccountNumbers struct {
	Number   uint64
	Sequence uint64
}

func GetAccountNumbers

func GetAccountNumbers(
	address string,
	grpcConn *grpc.ClientConn,
	encCfg app.EncodingConfig,
) (nums AccountNumbers, err error)

type BroadcastArgs

type BroadcastArgs struct {

	// clientCtx   sdkclient.Context // TODO: implement
	Broadcaster Broadcaster
	// contains filtered or unexported fields
}

type Broadcaster

type Broadcaster interface {
	BroadcastTxSync(txBytes []byte) (*sdk.TxResponse, error)
}

type BroadcasterGrpc

type BroadcasterGrpc struct {
	GRPC *grpc.ClientConn
}

func (BroadcasterGrpc) BroadcastTx

func (b BroadcasterGrpc) BroadcastTx(
	txBytes []byte, mode sdktypestx.BroadcastMode,
) (*sdk.TxResponse, error)

func (BroadcasterGrpc) BroadcastTxAsync

func (b BroadcasterGrpc) BroadcastTxAsync(
	txBytes []byte,
) (*sdk.TxResponse, error)

func (BroadcasterGrpc) BroadcastTxSync

func (b BroadcasterGrpc) BroadcastTxSync(
	txBytes []byte,
) (*sdk.TxResponse, error)

type BroadcasterTmRpc

type BroadcasterTmRpc struct {
	RPC cmtrpcclient.Client
}

func (BroadcasterTmRpc) BroadcastTxSync

func (b BroadcasterTmRpc) BroadcastTxSync(
	txBytes []byte,
) (*sdk.TxResponse, error)

type NetworkInfo

type NetworkInfo struct {
	// Nibiru EVM EIP-155 chain ID as an integer
	EvmChainID int64 `json:"evmChainID"`
	// Nibiru EVM EIP-155 chain ID
	EvmChainIDHex string `json:"evmChainIDHex"`
	// Nibiru EVM JSON-RPC server endpoint
	EvmRpc string `json:"evmRpc"`
	// Nibiru EVM JSON-RPC server endpoint from an archive node (no pruning)
	EvmRpcArchive string `json:"evmRpcArchive"`
	EvmWebsocket  string `json:"evmWebsocket"`

	CmtChainID        string `json:"cmtChainID"`
	GrpcEndpoint      string `json:"grpcEndpoint"`
	LcdEndpoint       string `json:"lcdEndpoint"`
	TmRpcEndpoint     string `json:"tmRpcEndpoint"`
	WebsocketEndpoint string `json:"websocketEndpoint"`
}

type NibiruSDK

type NibiruSDK struct {
	ChainId          string
	Keyring          keyring.Keyring
	EncCfg           app.EncodingConfig
	Querier          Querier
	CometRPC         cmtrpcclient.Client
	AccountRetriever authtypes.AccountRetriever
	GrpcClient       *grpc.ClientConn
}

func NewNibiruSdk

func NewNibiruSdk(
	chainId string,
	grpcConn *grpc.ClientConn,
	rpcEndpt string,
) (NibiruSDK, error)

func (*NibiruSDK) BroadcastMsgs

func (nc *NibiruSDK) BroadcastMsgs(
	from sdk.AccAddress,
	msgs ...sdk.Msg,
) (*sdk.TxResponse, error)

func (*NibiruSDK) BroadcastMsgsGrpc

func (nc *NibiruSDK) BroadcastMsgsGrpc(
	from sdk.AccAddress,
	msgs ...sdk.Msg,
) (*sdk.TxResponse, error)

func (*NibiruSDK) BroadcastMsgsGrpcWithSeq

func (nc *NibiruSDK) BroadcastMsgsGrpcWithSeq(
	from sdk.AccAddress,
	seq uint64,
	msgs ...sdk.Msg,
) (*sdk.TxResponse, error)

func (*NibiruSDK) BroadcastMsgsWithSeq

func (nc *NibiruSDK) BroadcastMsgsWithSeq(
	from sdk.AccAddress,
	seq uint64,
	msgs ...sdk.Msg,
) (*sdk.TxResponse, error)

func (*NibiruSDK) GetAccountNumbers

func (nc *NibiruSDK) GetAccountNumbers(
	address string,
) (nums AccountNumbers, err error)

func (*NibiruSDK) TxByHash

func (nc *NibiruSDK) TxByHash(txHashHex string) (*cmtcoretypes.ResultTx, error)

type Querier

type Querier struct {
	ClientConn *grpc.ClientConn

	// Smart Contracts
	EVM  evm.QueryClient
	Wasm wasm.QueryClient

	// Other Modules
	Devgas       devgas.QueryClient
	Epoch        epochs.QueryClient
	Inflation    inflation.QueryClient
	TokenFactory tokenfactory.QueryClient
	// contains filtered or unexported fields
}

func NewQuerier

func NewQuerier(
	grpcConn *grpc.ClientConn,
	cmtRpc cmtrpcclient.Client,
) (Querier, error)

func (Querier) TxByHash added in v2.8.0

func (q Querier) TxByHash(txHashHex string) (*cmtcoretypes.ResultTx, error)

Jump to

Keyboard shortcuts

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