Skip to content

Providers

Koios

Koios is a distributed & open-source public API query layer for Cardano, that is elastic in nature and addresses ever-demanding requirements from Cardano Blockchain.

INFO

XRAY/Network manages a standalone Koios cluster, which is the default data provider (and explorer) for CW3js. Unauthenticated uses a basic tariff with limits on requests from Origin and IP addresses, so be aware that if the load on your application grows, you should switch to paid tariffs or original Koios, or recharge XRAY/Graph.

Usage examples

ts
import { CardanoWeb3, KoiosProvider } from "cardano-web3-js"

const web3 = await CardanoWeb3.init({
  provider: new KoiosProvider(
    "https://api.koios.rest/api/v1",
    {}, // pass custom haeders if needed
  )
})

const tip = await web3.provider.getTip()
console.log(tip)
ts
import { CardanoWeb3 } from "cardano-web3-js"

const web3 = await CardanoWeb3.init({
  provider: new KoiosProvider(
    "https://api.koios.rest/api/v1",
    {}, // pass custom haeders if needed
  )
})

const utxos = await web3.provider.getUtxosByAddress("addr1...")
console.log(utxos)
ts
import { CardanoWeb3 } from "cardano-web3-js"

const web3 = await CardanoWeb3.init({
  provider: new KoiosProvider(
    "https://api.koios.rest/api/v1",
    {}, // pass custom haeders if needed
  )
})

const datum = await web3.provider.getDatumByHash("hash...")
const script = await web3.provider.getScriptByHash("hash...")
console.log(datum)
console.log(script)

Kupmios (Kupo & Ogmios)

Kupo is a fast, lightweight and customizable chain index for Cardano, and Ogmios is a JSON/RPC bridge for Cardano. These tools allow you to retrieve data from the chain and monitor the state of the chain.

INFO

XRAY/Network manages a standalone Ogmios and Kupo (with the match all parameter) cluster. Unauthenticated uses a basic tariff with limits on requests from Origin and IP addresses, so be aware that if the load on your application grows, you should switch to paid tariffs and recharge XRAY/Graph.

Usage examples

ts
import { CardanoWeb3 } from "cardano-web3-js"

const web3 = await CardanoWeb3.init({
  provider: new KupmiosProvider({
    ogmiosUrl: "https://ogmios.com/api",
    kupoUrl: "https://kupo.com/api",
    ogmiosHeaders: {}, // pass custom headers
    kupoHeaders: {}, // pass custom headers
  }),
})

const tip = await web3.provider.getTip()
console.log(tip)
ts
import { CardanoWeb3 } from "cardano-web3-js"

const web3 = await CardanoWeb3.init({
  provider: new KupmiosProvider({
    ogmiosUrl: "https://ogmios.com/api",
    kupoUrl: "https://kupo.com/api",
    ogmiosHeaders: {}, // pass custom headers
    kupoHeaders: {}, // pass custom headers
  }),
})

const utxos = await web3.provider.getUtxosByAddress("addr1...")
console.log(utxos)
ts
import { CardanoWeb3 } from "cardano-web3-js"

const web3 = await CardanoWeb3.init({
  provider: new KupmiosProvider({
    ogmiosUrl: "https://ogmios.com/api",
    kupoUrl: "https://kupo.com/api",
    ogmiosHeaders: {}, // pass custom headers
    kupoHeaders: {}, // pass custom headers
  }),
})

const datum = await web3.provider.getDatumByHash("hash...")
const script = await web3.provider.getScriptByHash("hash...")
console.log(datum)
console.log(script)

Mastering Custom Provider

Provider interface must implements Provider type

ts
import { T } from "cardano-web3-js"


const NewProvider = (): T.Provider => {
  return {
    ...
  }
}

Released under the MIT License