Koios Provider

Distributed & open-source public API query layer for Cardano

Koios provides a query layer which allows your app to access information stored on the blockchain.

Get started:

import { KoiosProvider } from "@meshsdk/core";

const blockchainProvider = new KoiosProvider(
  'preprod', // "api" | "preview" | "preprod" | "guild"
  '<Your-API-Key>',
);

Get data from URL

You can fetch any data from the blockchain by providing the URL path.

await blockchainProvider.get('/addresses/addr_test1qpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0uafhxhu32dys6pvn6wlw8dav6cmp4pmtv7cc3yel9uu0nq93swx9/transactions')
Get data from URL

Fetch data from the blockchain

Fetch Account Info

Obtain information about a specific stake account.

await blockchainProvider.fetchAccountInfo('stake_test1uzw5mnt7g4xjgdqkfa80hrk7kdvds6sa4k0vvgjvlj7w8eskffj2n')
Fetch Account Info

Fetch account info using stake address

Fetch Address Assets

Fetch assets from an address.

await blockchainProvider.fetchAddressAssets('addr_test1qpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0uafhxhu32dys6pvn6wlw8dav6cmp4pmtv7cc3yel9uu0nq93swx9')
Fetch Address UTxOs

Fetch UTxOs from address

await blockchainProvider.fetchAddressAssets(
  'addr_test1qpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0uafhxhu32dys6pvn6wlw8dav6cmp4pmtv7cc3yel9uu0nq93swx9'
);
Fetch assets from address

Fetch assets given an address

await blockchainProvider.fetchAddressAssets(
  'addr_test1qpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0uafhxhu32dys6pvn6wlw8dav6cmp4pmtv7cc3yel9uu0nq93swx9',
);

Fetch Address UTxOs

Fetch UTxOs controlled by an address.

await blockchainProvider.fetchAddressUTxOs('addr_test1qpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0uafhxhu32dys6pvn6wlw8dav6cmp4pmtv7cc3yel9uu0nq93swx9')

Optionally, you can filter UTXOs containing a particular asset by providing asset, where it is the concatenation of policy ID and asset.

await fetchAddressUTxOs(address: string, asset?: string)
Fetch Address UTxOs

Fetch UTxOs from address

await blockchainProvider.fetchAddressUTxOs(
  'addr_test1qpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0uafhxhu32dys6pvn6wlw8dav6cmp4pmtv7cc3yel9uu0nq93swx9'
);
Fetch UTxOs with Asset

Fetch UTxOs from address with asset

await blockchainProvider.fetchAddressUTxOs(
  'addr_test1qpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0uafhxhu32dys6pvn6wlw8dav6cmp4pmtv7cc3yel9uu0nq93swx9',
  'd9312da562da182b02322fd8acb536f37eb9d29fba7c49dc172555274d657368546f6b656e'
);

Fetch Asset Addresses

Fetch a list of a addresses containing a specific asset where it is the concatenation of policy ID and asset.

await blockchainProvider.fetchAssetAddresses('d9312da562da182b02322fd8acb536f37eb9d29fba7c49dc172555274d657368546f6b656e')
Fetch Asset Addresses

Fetch list of addresses containing a specific asset

Fetch Asset Metadata

Fetch the asset metadata by providing asset's unit, which is the concatenation of policy ID and asset name in hex.

await blockchainProvider.fetchAssetMetadata('d9312da562da182b02322fd8acb536f37eb9d29fba7c49dc172555274d657368546f6b656e')
Fetch Asset Metadata

Fetch metadata from asset ID

Fetch Block Info

Fetch block infomation. You can get the hash from fetchTxInfo().

await blockchainProvider.fetchBlockInfo('79f60880b097ec7dabb81f75f0b52fedf5e922d4f779a11c0c432dcf22c56089')
Fetch Block Info

Fetch information about a block

Fetch Collection Assets

Fetch a list of assets belonging to a collection by providing its Policy ID.

await blockchainProvider.fetchCollectionAssets('d9312da562da182b02322fd8acb536f37eb9d29fba7c49dc17255527')

The API will return a list of assets and a cursor next. If the cursor is not null, you can use it to fetch the next page of results. Here is an example of the response.

{
  "assets": [
    {
      "unit": "d9312da562da182b02322fd8acb536f37eb9d29fba7c49dc17255527",
      "quantity": "1"
    },
  ],
  "next": 2
}

The fetchCollectionAssets function also accepts an optional cursor parameter to fetch the next page of results. The default value is 1.

await fetchCollectionAssets(
  policyId: string,
  cursor = 1
)
Fetch Collection Assets

Fetch list of assets belonging to a collection and its quantity

Fetch Handle Address

ADA Handle allows users to use a human-readable "Handle" to associate an address.

Each Handle is a unique NFT, minted and issued on the Cardano blockchain. These NFTs act as unique identifiers for the UTXO that they reside in.

We can resolve the handle's address with fetchHandleAddress.

await blockchainProvider.fetchHandleAddress('meshsdk')
Fetch Handle Address

Fetch address by handle

Fetch Handle

ADA Handle allows users to use a human-readable "Handle" to associate an address.

Each Handle is a unique NFT, minted and issued on the Cardano blockchain. These NFTs act as unique identifiers for the UTXO that they reside in.

ADA Handle also released a CIP68 handle and this function will fetch the metadata of the handle.

await blockchainProvider.fetchHandle('meshsdk')
Fetch Handle

Fetch handle metadata

Fetch Protocol Parameters

Fetch the latest protocol parameters.

await blockchainProvider.fetchProtocolParameters()

Optionally, you can provide an epoch number to fetch the protocol parameters of that epoch.

Fetch Protocol Parameters

Fetch protocol parameters of the blockchain by epoch

Fetch Transaction Info

Fetch transaction infomation. Only confirmed transaction can be retrieved.

await blockchainProvider.fetchTxInfo('f4ec9833a3bf95403d395f699bc564938f3419537e7fb5084425d3838a4b6159')
Fetch Transaction Info

Fetch information about a transaction

Submit Transaction

Submit a serialized transaction to the network.

await blockchainProvider.submitTx(signedTx);

On Transaction Confirmed

Allow you to listen to a transaction confirmation. Upon confirmation, the callback will be called.

const tx = new Transaction({ initiator: wallet });
tx.sendLovelace('addr_test1vpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0c7e4cxr', '5000000');

const unsignedTx = await tx.build();
const signedTx = await wallet.signTx(unsignedTx);
const txHash = await wallet.submitTx(signedTx);

blockchainProvider.onTxConfirmed(txHash, () => {
  // Transaction confirmed
});