You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

cardano-koios-client

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cardano-koios-client

TypeScript client for XRAY/Graph Koios Tiny API and original Koios.REST API

1.0.10
latest
Source
npmnpm
Version published
Weekly downloads
108
58.82%
Maintainers
1
Weekly downloads
 
Created
Source

Discord NPM CODEQL

TypeScript Client for XRAY/Graph Koios Tiny and Koios.REST API

Automatically generated Openapi-fetch (Axios) client for Koios Cardano RESTful API based on schema.yaml OpenAPI schema. Works great with XRAY/Graph Koios Tiny and the original Koios

Installation

To install the client with Yarn, run:

yarn install cardano-koios-client

To install the client with NPM, run:

npm i cardano-koios-client

Usage

import KoiosClient from "cardano-koios-client"

const client = KoiosClient("https://api.koios.rest/api/v1")

const app = async () => {
  const tip = await client.GET("/tip")

  if (tip.data) {
    console.log(tip.data?.[0]?.block_no)
  }
  if (tip.error) {
    console.error(tip.error)
  }
}

app()

Advanced Usage

Headers / Query Params

Read https://api.koios.rest/#overview--api-usage for more information

import KoiosClient from "cardano-koios-client"

const baseUrl = "https://api.koios.rest/api/v1"
const headers = {} // rest headers
const client = KoiosClient(baseUrl, headers)

const app = async () => {
  const blocks = await client.GET("/blocks", {
    headers: { "Content-Type": "application/json" }, // one shot headers
    params: { 
      query: { 
        limit: 1,
        offset: 100,
        epoch_no: "eq.250",
      },
    },
  })

  console.log(blocks.data)
}

app()
Request Cancellation (AbortSignal)
import KoiosClient from "cardano-koios-client"

const client = KoiosClient("https://api.koios.rest/api/v1")

const app = async () => {
  const abortController = new AbortController()

  setTimeout(() => {
    abortController.abort() // cancel request
    console.log('Aborted!')
  }, 200)

  const tip = await client.GET("/tip", {
    signal: abortController.signl,
  })

  if (tip.data) {
    console.log(tip.data?.[0]?.block_no)
  }
  if (tip.error) {
    console.error(tip.error)
  }
}

app()

Endpoints

API URLs

Managed by Cardano Community (Koios Elastic Query Layer, HAproxy Balancer)

https://api.koios.rest/api/v1
https://preprod.koios.rest/api/v1
https://preview.koios.rest/api/v1
https://guild.koios.rest/api/v1

Managed by XRAY/Network (XRAY/Graph, Cloudflare WAF & Load Balancer)

https://graph.xray.app/output/koios/mainnet/api/v1
https://graph.xray.app/output/koios/preprod/api/v1
https://graph.xray.app/output/koios/preview/api/v1

FAQs

Package last updated on 19 May 2025

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