Skip to main content

GO


Koios API Client Library for Go

Overview

A GO package for Cardano Blockchain using Koios API

Below there is an example to study, while to see the full koios-go-client documentation you can find it here

Install

Tips

To install the module, type the following command:

go get github.com/cardano-community/koios-go-client/v3

Import the module

Tips

To use the module, see the following example:

import (
  "github.com/cardano-community/koios-go-client/v3" // imports as package "koios"
)

Examples

Basic usage
package main

import (
	"context"
	"fmt"
	"log"

	koios "github.com/cardano-community/koios-go-client/v3"
)

func main() {
  // Call to koios.New without options is same as calling it with default opts.
  // See godoc for available configuration options.
  // api, err := koios.New(
  // 	koios.Host(koios.MainnetHost),
  // 	koios.APIVersion(koios.DefaultAPIVersion),
  // 	koios.Port(koios.DefaultPort),
  // 	koios.Schema(koios.DefaultSchema),
  // 	koios.HttpClient(koios.DefaultHttpClient),
  // ).
  api, err := koios.New()
  if err != nil {
    log.Fatal(err)
  }

  res, err := api.GetTip(context.Background(), nil)
  if err != nil {
	  log.Fatal(err)
  }
  fmt.Println("status: ", res.Status)
  fmt.Println("statu_code: ", res.StatusCode)

  fmt.Println("abs_slot: ", res.Data.AbsSlot)
  fmt.Println("block_no: ", res.Data.BlockNo)
  fmt.Println("block_time: ", res.Data.BlockTime)
  fmt.Println("epoch: ", res.Data.Epoch)
  fmt.Println("epoch_slot: ", res.Data.EpochSlot)
  fmt.Println("hash: ", res.Data.Hash)
}