1

The Cardano ecosystem has a mountain of various tools for querying the chain. Here are a few I'm aware of

  • Ogmios
  • Cardano-Wallet
  • dbsync
  • Cardano-graphql
  • koios

We would like to retrieve all information related to a transaction (sender, receiver, amounts, insertion slot, etc). What is the best tool for doing that as of today?

2 Answers 2

1

Here is how you do it using cardano-graphql:

  {
    transactions(where: { hash: { _eq: "4c827fe1c193de7924b19696965d21a34df04fed99a35428b22d475dbc999cc3"} })   {
      block {
        epoch {
          number
        }
        epochNo
        fees
        forgedAt

        hash
      }
      blockIndex
      deposit
      fee
      hash
      inputs {
        address
          txHash
      }
      invalidBefore
      invalidHereafter
      scriptSize
      size
      totalOutput
      includedAt
      validContract
    }
  }

You can use Dandelion and paste this code in there to retrieve the information requested. You can even play with the different data types (check the "DOCS" tab for reference) and add/remove the ones you want.

If you want a real implementation of this, you can refer to the following TypeScript code:

import axios from "axios";

export async function getTransaction(txHash: string) {
  
  const url = `https://graphql-api.testnet.dandelion.link`;

  const headers = {
    "content-type": "application/json"
  };

  const query = `
  {
    transactions(where: { hash: { _eq: "${txHash}"} })  {
      block {
        epoch {
          number
        }
        epochNo
        fees
        forgedAt

        hash
      }
      blockIndex
      deposit
      fee
      hash
      inputs {
        address
          txHash
      }
      invalidBefore
      invalidHereafter
      scriptSize
      size
      totalOutput
      includedAt
      validContract
    }
  }
`;

  const graphqlQuery = {
      "query": query
  };

  const response = await axios({
    url,
    method: 'post',
    headers: headers,
    data: graphqlQuery
  });

  return response.data;

}

I'm using axios library to handle the request to Dandelion.

1

GraphQL is probably the easiest in my option and offers the most room for growth.

The public GraphQL API hosted by Dandelion (https://graphql-api.testnet.dandelion.link) is a great place to learn and get started with GraphQL. I suggest hosting your own GraphQL Servers so you can query larger and more advanced data sets.

Blockfrost.io and Tangcrypto are honorable mentions, which will allow you get data from the Cardano Blockchain but have daily free limits. It is possible to get mostly all the data you need from one of the Blockfrost or Tangcrypto, but you will mosy likely need to execute multiple queries to get all the info you want.

There is another open-source API that is free and in the process of being created. I found it a few months ago but forgot the link, it was like the blockfront API but a little more in-depth and advanced, and it was all free with unlimited queries. If I find it ill again ill add it.

Short answer GraphQL is the best, and blockfrost is the most convenient.

@RdLrT also suggested https://api.koios.rest/

1
  • 1
    I assume you meant koios? It's already part of OP's list
    – RdLrT
    Jun 5, 2022 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.