client

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2024 License: Apache-2.0 Imports: 14 Imported by: 7

README

celestia-openrpc

celestia-openrpc is a golang client for celestia-node RPC, without depenencies on celestia-node/celestia-app/cosmos-sdk.

This client library is useful for environments where dependencies on celestia-node/celestia-app/cosmos-sdk are not possible or desired.

Examples

For a full tutorial on how to use this library, visit the official guide.

For more examples, see the examples directory.

Create a new client and submit and fetch a blob
import (
	"bytes"
	"context"
	"fmt"

	client "github.com/celestiaorg/celestia-openrpc"
	"github.com/celestiaorg/celestia-openrpc/types/blob"
	"github.com/celestiaorg/celestia-openrpc/types/share"
	"github.com/celestiaorg/rsmt2d"
)

func main() {
	SubmitBlob(context.Background(), "ws://localhost:26658", "JWT_TOKEN")
}

// SubmitBlob submits a blob containing "Hello, World!" to the 0xDEADBEEF namespace. It uses the default signer on the running node.
func SubmitBlob(ctx context.Context, url string, token string) error {
	client, err := client.NewClient(ctx, url, token)
	if err != nil {
		return err
	}

	// let's post to 0xDEADBEEF namespace
	namespace, err := share.NewBlobNamespaceV0([]byte{0xDE, 0xAD, 0xBE, 0xEF})
	if err != nil {
		return err
	}

	// create a blob
	helloWorldBlob, err := blob.NewBlobV0(namespace, []byte("Hello, World!"))
	if err != nil {
		return err
	}

	// submit the blob to the network
	height, err := client.Blob.Submit(ctx, []*blob.Blob{helloWorldBlob}, blob.DefaultGasPrice())
	if err != nil {
		return err
	}

	fmt.Printf("Blob was included at height %d\n", height)

	// fetch the blob back from the network
	retrievedBlobs, err := client.Blob.GetAll(ctx, height, []share.Namespace{namespace})
	if err != nil {
		return err
	}

	fmt.Printf("Blobs are equal? %v\n", bytes.Equal(helloWorldBlob.Commitment, retrievedBlobs[0].Commitment))
	return nil
}

Documentation

Index

Constants

View Source
const AuthKey = "Authorization"

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Fraud  fraud.API
	Blob   blob.API
	Header header.API
	State  state.API
	Share  share.API
	DAS    das.API
	P2P    p2p.API
	Node   node.API
	DA     da.API
	// contains filtered or unexported fields
}

func NewClient

func NewClient(ctx context.Context, addr string, token string) (*Client, error)

func (*Client) Close

func (c *Client) Close()

Close closes the connections to all namespaces registered on the client.

Directories

Path Synopsis
examples
types
da
das
p2p
sdk

Jump to

Keyboard shortcuts

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