Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

  • v1.4.0
  • Source
  • Go
  • Socket score

Version published
Created
Source

Koios API Client Library for Go

Koios API is Elastic Cardano Query Layer!

A consistent query layer for developers to build upon Cardano, with multiple, redundant endpoints that allow for easy scalability.

Koios API Client Library for Go

Note that github.com/cardano-community/koios-go-client is considered unstable and may receive BREAKING CHANGES work of github.com/cardano-community/koios-go-client/v2 is done in v2 branch see also related PR #34

PkgGoDev

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

There is CLI Application to interact with Koios API from Command-line see:

koios cli repository for souce and installing instruction of koios cli

Build Status

linux macos windows

Development Status

GitHub last commit codecov codeql misspell Go Report Card



Usage

See Godoc PkgGoDev

Additionally you can find all usecases by looking source of koio-cli Command-line application koios-cli which utilizes entire API of this library.

NOTE

Library normalizes some of the API responses and constructs Typed response for each end point. If you wish to work with *http.Response directly you can do so by using api client GET,POST, HEAD methods.

Basic usage

package main

import (
	"context"
	"fmt"
	"log"

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

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)
}

Concurrency using goroutines

This library is thread-safe so you can freerly use same api client instance passing it to your goroutines.

Following example uses goroutines to query chain tip from different endpoints.

func main() {
  api, _ := koios.New(
    // limit client request 1 per second even though
    // this example will send requests in goroutines.
    koios.RateLimit(1),
  )
  ctx := context.Background()
  var wg sync.WaitGroup
  servers := []string{
    "api.koios.rest",
    "guild.koios.rest",
    "testnet.koios.rest",
  }

  // Thanks to rate limit option requests will be made
  // once in a second.
  for _, host := range servers {
    wg.Add(1)
    go func(ctx context.Context, host string) {
      defer wg.Done()
      // switching host by creating light clone of client
      // with new options
      client, err := api.WithOptions(koios.Host(host))
      res, _ := client.GET(ctx, "/tip", nil)
      defer res.Body.Close()
      body, _ := io.ReadAll(res.Body)
      fmt.Println("Host: ", host)
      fmt.Println("Response: ", string(body))
    }(ctx, host)
  }

  wg.Wait()
}

Lovelace (math on ada, assets and tokens).

Library uses for most cases to represent lovelace using Lovelace data type.

For decimal package API see

Implemented Endpoints

endpointGo APICLI commandAPI Doc
NETWORK
/tip*.GetTip(...) *TipResponsetip
/genesis*.GetGenesis(...) *GenesisResponsegenesis
/totals*.GetTotals(...) *TotalsResponsetotals
EPOCH
/epoch_info*.GetEpochInfo(...) *EpochInfoResponseepoch-info
/epoch_params*.GetEpochParams(...) *EpochParamsResponseepoch-params
BLOCK
/blocks*.GetBlocks(...) *BlocksResponseblocks
/block_info*.GetBlocksInfo(...) *BlocksInfoResponseblocks-info
*.GetBlockInfo(...) *BlockInfoResponseblock-info
/block_txs*.GetBlockTxs(...) *BlockTxsResponseblock-txs
TRANSACTIONS
/tx_info*.GetTxsInfos(...) *TxsInfoResponsetxs-info
*.GetTxInfo(...) *TxInfoResponsetx-info
/tx_utxos*.GetTxUTxOs(...) *TxUTxOsResponsetx-utxos
/txs_utxos*.GetTxsUTxOs(...) *TxsUTxOsResponsetxs-utxos
/tx_metadata*.GetTxsMetadata(...) *TxsMetadataResponsetxs-metadata
*.GetTxMetadata(...) *TxMetadataResponsetx-metadata
/tx_metalabels*.GetTxMetaLabels(...) *TxMetaLabelsResponsetx-metalabels
/submittx*.SubmitSignedTx(...) *SubmitSignedTxResponsetx-submit
/tx_status*.GetTxsStatuses(...) *TxsStatusesResponsetxs-statuses
*.GetTxStatus(...) *TxStatusResponsetx-status
ADDRESS
/address_info*.GetAddressInfo(...) *AddressInfoResponseaddress-info
/address_txs*.GetAddressTxs(...) *AddressTxsResponseaddress-txs
/address_assets*.GetAddressAssets(...) *AddressAssetsResponseaddress-assets
/credential_txs*.GetCredentialTxs(...) *CredentialTxsResponsecredential-txs
ACCOUNT
/account_list*.GetAccountList(...) *AccountListResponseaccount-list
/account_info*.GetAccountInfo(...) *AccountListResponseaccount-info
/account_rewards*.GetAccountRewards(...) *AccountRewardsResponseaccount-rewards
/account_updates*.GetAccountUpdates(...) *AccountUpdatesResponseaccount-updates
/account_addresses*.GetAccountAddresses(...) *AccountAddressesResponseaccount-addresses
/account_assets*.GetAccountAssets(...) *AccountAssetsResponseaccount-assets
/account_history*.GetAccountHistory(...) *AccountHistoryResponseaccount-history
ASSET
/asset_list*.GetAssetList(...) *AssetAddressListResponseasset-list
/asset_address_list*.GetAssetAddressList(...) *AssetAddressListResponseasset-address-list
/asset_info*.GetAssetInfo(...) *AssetInfoResponseasset-info
/asset_history*.GetAssetHistory(...) *AssetHistoryResponseasset-history
/asset_policy_info*.GetAssetPolicyInfo(...) *AssetPolicyInfoResponseasset-policy-info
/asset_summary*.GetAssetSummary(...) *AssetSummaryResponseasset-summary
/asset_txs*.GetAssetTxs(...) *AssetTxsResponseasset-txs
POOL
/pool_list*.GetPoolList(...) *PoolListResponsepool-list
/pool_info*.GetPoolInfos(...) *PoolInfoResponsepool-infos
*.GetPoolInfo(...) *PoolInfoResponsepool-info
/pool_delegators*.GetPoolDelegators(...) *PoolDelegatorsResponsepool-delegators
/pool_blocks*.GetPoolBlocks(...) *PoolBlocksResponsepool-blocks
/pool_history*.GetPoolHistory(...) *PoolHistoryResponsepool-history
/pool_updates*.GetPoolUpdates(...) *PoolUpdatesResponsepool-updates
/pool_relays*.GetPoolRelays(...) *PoolRelaysResponsepool-relays
/pool_metadata*.GetPoolMetadata(...) *PoolMetadataResponsepool-metadata
SCRIPT
/native_script_list*.GetNativeScriptList(...) *NativeScriptListResponsenative-script-list
/plutus_script_list*.GetPlutusScriptList(...) *PlutusScriptListResponseplutus-script-list
/script_redeemers*.GetScriptRedeemers(...) *ScriptRedeemersResponsescript-redeemers

Contributing

We would love for you to contribute to Koios API Client Library for Go and help make it even better than it is today! As a contributor, here are the guidelines we would like you to follow:

Code of Conduct

Help us keep Koios API Client Library for Go open and inclusive. Please read and follow our Code of Conduct


Got a Question or Problem?

Do not open issues for general support questions as we want to keep GitHub issues for bug reports and feature requests. You've got much better chances of getting your question answered on Koios Telegram Group


Issues and Bugs

If you find a bug in the source code, you can help us by submitting an issue to our GitHub Repository. Even better, you can submit a Pull Request with a fix.


Feature Requests

You can request a new feature by submitting an issue to our GitHub Repository. If you would like to implement a new feature, please submit an issue with a proposal for your work first, to be sure that we can use it. Please consider what kind of change it is:

  • For a Major Feature, first open an issue and outline your proposal so that it can be discussed. This will also allow us to better coordinate our efforts, prevent duplication of work, and help you to craft the change so that it is successfully accepted into the project.
  • Small Features can be crafted and directly submitted as a Pull Request.

Submission Guidelines

Submitting an Issue

Before you submit an issue, please search the issue tracker, maybe an issue for your problem already exists and the discussion might inform you of workarounds readily available.

You can file new issues by filling out our new issue form.


Submitting a Pull Request (PR)

Before you submit your Pull Request (PR) consider the following guidelines:

  1. Search GitHub for an open or closed PR that relates to your submission. You don't want to duplicate effort.

  2. Fork the cardano-community/koios-go-client repo.

  3. Setup you local repository

    git@github.com:<your-github-username>/koios-go-client.git
    cd koios-go-client
    git remote add upstream git@github.com:cardano-community/koios-go-client.git
    
  4. Make your changes in a new git branch and ensure that you always start from up to date main branch. Repeat this step every time you are about to start woking on new PR.

    e.g. Start new change work to update readme:

    # if you are not in main branch e.g. still on previous work branch
    git checkout main
    git pull --ff upstream main
    git checkout -b update-readme main
    
  5. Create your patch, including appropriate test cases.

  6. Follow our Coding Rules.

  7. If changes are in source code except documentations then run the full test suite, as described in the developer documentation, and ensure that all tests pass.

  8. Commit your changes using a descriptive commit message that follows our commit message conventions. Adherence to these conventions is necessary because release notes are automatically generated from these messages.

    git add -A
    git commit --signoff
    # or in short
    git commit -sm"docs(markdown): update readme examples"
    
  9. Push your branch to GitHub:

    git push -u origin update-readme
    
  10. In GitHub, send a pull request to main branch.

  • If we suggest changes then:
    • Make the required updates.

    • Re-run the test suites to ensure tests are still passing.

    • Rebase your branch and force push to your GitHub repository (this will update your Pull Request):

      git fetch --all
      git rebase upstream main
      git push -uf origin update-readme
      

That's it! Thank you for your contribution!


After your pull request is merged

After your pull request is merged, you can safely delete your branch and pull the changes from the main (upstream) repository:

  • Delete the remote branch on GitHub either through the GitHub web UI or your local shell as follows:

    git push origin --delete update-readme
    
  • Check out the main branch:

    git checkout main -f
    
  • Delete the local branch:

    git branch -D update-readme
    
  • Update your master with the latest upstream version:

    git pull --ff upstream main
    

Coding Rules

To ensure consistency throughout the source code, keep these rules in mind as you are working:

  • All features or bug fixes must be tested by one or more specs (unit-tests).
  • All public API methods must be documented.

Commit Message Guidelines

Conventional Commits

We have very precise rules over how our git commit messages can be formatted. This leads to more readable messages that are easy to follow when looking through the project history. Commit messages should be well formatted, and to make that "standardized", we are using Conventional Commits. Our release workflow uses these rules to generate changelogs.


Commit Message Format

Each commit message consists of a header, a body and a footer. The header has a special format that includes a type, a scope and a subject:

<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>

When maintainers are merging PR merge commit should be edited:

<type>(<scope>): <subject> (#pr)
<BLANK LINE>
<body>
<BLANK LINE>
<footer>

The header is mandatory and the scope of the header is optional.

Any line of the commit message cannot be longer 100 characters! This allows the message to be easier to read on GitHub as well as in various git tools.

The footer should contain a closing reference to an issue if any.

Samples:

docs(markdown): update readme examples

fix(endpoint): update Tip endpoint to latest specs.

description of your change.
refactor(client): change Client GET function signature

change order of client GET method arguments.

BREAKING CHANGE: Clien.Get signature has changed

Revert

If the commit reverts a previous commit, it should begin with revert: , followed by the header of the reverted commit. In the body it should say: This reverts commit <hash>., where the hash is the SHA of the commit being reverted.


Type

Must be one of the following:

  • build: Changes that affect the build system or external dependencies (example scopes: goreleaser, taskfile)
  • chore: Other changes that don't modify src or test files.
  • ci: Changes to our CI configuration files and scripts.
  • dep: Changes related to dependecies e.g. go.mod
  • docs: Documentation only changes (example scopes: markdown, godoc)
  • feat: A new feature
  • fix: A bug fix
  • perf: A code change that improves performance
  • refactor: A code change that neither fixes a bug nor adds a feature
  • revert: Reverts a previous commit
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  • test: Adding missing tests or correcting existing tests

Scope

The following is the list of supported scopes:

scopedescription
clientAPI client related changes
endpointChanges related to api endpoints
godocGo documentation
markdownMarkdown files

Subject

The subject contains a succinct description of the change:

  • use the imperative, present tense: "change" not "changed" nor "changes"
  • don't capitalize the first letter
  • no dot (.) at the end
Body

Just as in the subject, use the imperative, present tense: "change" not "changed" nor "changes". The body should include the motivation for the change and contrast this with previous behavior.

The footer should contain any information about Breaking Changes and is also the place to reference GitHub issues that this commit Closes.

Breaking Changes should start with the word BREAKING CHANGE: with a space or two newlines. The rest of the commit message is then used for this.

A detailed explanation can be found in this [document][commit-message-format].


Development Documentation

Setup your machine

Prerequisites:

Setup local env

task setup

Lint your code

task lint

Test your change

task test

View code coverage report from in browser (results from task test)

task cover

Credits

GitHub contributors

Original author.
koios-go-client was moved under Cardano Community from howijd/koios-rest-go-client

FAQs

Package last updated on 02 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc