node

package
v0.0.0-...-5d200cf Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

README

Node

GoDoc

Package node provides an interface for cardano backends/nodes. Node implements two backends; blockfrost API and cardano-cli.

Installation

go get github.com/milos-ethernal/go-cardano-serialization/node

Usage

Basic usage on how to setup a Blockfrost Node on testnet and query for utxos for an address.

package main

import (
    "fmt"
    "log"
    "github.com/milos-ethernal/go-cardano-serialization/node"
)

func prettyPrint(v interface{}) string {
	bytes, _ := json.MarshalIndent(v, "", "	")
	return string(bytes)
}

func main() {
    cli := node.NewBlockfrostClient(
		os.Getenv("BLOCKFROST_PROJECT_ID"),
		network.TestNet(),
	)

    addr, err := address.NewAddress(
        "addr_test1qqe6zztejhz5hq0xghlf72resflc4t2gmu9xjlf73x8dpf88d78zlt4rng3ccw8g5vvnkyrvt96mug06l5eskxh8rcjq2wyd63"
    )
    if err != nil {
        log.Fatal(err)
    }

    utxos, err := cli.UTXOs(addr)
    if err != nil {
        log.Fatal(err)
    }

    prettyPrint(utxos)
}

More examples on node usage can be found in the examples

License

Licensed under the Apache License 2.0, see LICENSE

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SubmitTx

func SubmitTx(transaction []byte) (int, string)

Types

type NetworkTip

type NetworkTip struct {
	Slot  uint `json:"slot,omitempty"`
	Epoch uint `json:"epoch,omitempty"`
	Block uint `json:"block,omitempty"`
}

NetworkTip contains parameters from the tip of the network

type Node

type Node interface {
	// UTXOs returns list of unspent transaction outputs
	UTXOs(address.Address) ([]tx.TxInput, error)

	// SubmitTx submits a cbor marshalled transaction to the cardano blockchain
	// using blockfrost or cardano-cli
	SubmitTx(tx.Tx) (string, error)

	// ProtocolParameters returns Protocol Parameters from the network
	ProtocolParameters() (protocol.Protocol, error)

	// QueryTip returns the tip of the network for use in tx building
	//
	// Using `query tip` on cardano-cli requires a synced local node
	QueryTip() (NetworkTip, error)
}

func NewBlockfrostClient

func NewBlockfrostClient(projectId string, network *network.NetworkInfo) Node

NewBlockfrostClient returns a wrapper for the blockfrost API/SDK with Node interface

func NewCardanoCliNode

func NewCardanoCliNode(network *network.NetworkInfo, cliPaths ...string) Node

NewCardanoCliNode returns a wrapper for the cardano-cli with the Node interface

Jump to

Keyboard shortcuts

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