0

Is there any API for this out already?

I'm looking for an API that:

  1. Given a tx hash, can get the block # and info about the block which the transaction was in
  2. get current block # and info about current block

3 Answers 3

1

Using Blockfrost.io API:

  1. For transaction hash dbbf5116280f83bb6d3d117ef0b41ca52b0bb85f417f761bd42d1903286743e6:

You can find the block height:

 $ curl -s https://cardano-mainnet.blockfrost.io/api/v0/txs/dbbf5116280f83bb6d3d117ef0b41ca52b0bb85f417f761bd42d1903286743e6 -H 'project_id: xxx' \
  | jq .block_height
8369736

And use that block height to get more information about the given block.

$ curl -s https://cardano-mainnet.blockfrost.io/api/v0/blocks/8369736 -H 'project_id: x'  | jq
{
  "time": 1675778106,
  "height": 8369736,
  "hash": "0fa8c39c9c30ebb14b64781cca63d326a3c57154dfb590d63c0d3eb7850cc4ec",
  "slot": 84211815,
  "epoch": 392,
  "epoch_slot": 231015,
  "slot_leader": "pool1q7wrwstqkzhrffdzpw8ftfd4epmxywdjnp8384atjcnezchv242",
  "size": 88902,
  "tx_count": 35,
  "output": "22093283458254",
  "fees": "11180120",
  "block_vrf": "vrf_vk1uatrt2xzhxs382ss5u9mr20aahzx8s000c077xerulzy22dzxy3qc0r6qv",
  "op_cert": "9c6689a625fb22cd17df084718f232155a15a73b56103a96a117e5d4a58f95a8",
  "op_cert_counter": "10",
  "previous_block": "055462536b48a16b91552ff05df0760d2191c044ec419f2f93d9c7a894aaecde",
  "next_block": "f63f3ed7140524bffc1a975a177f93cf72b426201f9ea5a82cb059a7ed1b53df",
  "confirmations": 10
}
  1. For the current block number, just use /api/v0/blocks/latest.
1

If you looking for a simple web API, the most popular choice is Blockfrost: https://docs.blockfrost.io/#tag/Cardano-Blocks/paths/~1blocks~1%7Bhash_or_number%7D/get https://docs.blockfrost.io/#tag/Cardano-Blocks/paths/~1blocks~1latest/get

which has a generous free tier. An alternative is Koios: https://api.koios.rest/#overview

If you want to run some infrastructure yourself, have a look at:

Ogmois: https://ogmios.dev/ or Oura: https://github.com/txpipe/oura

specifically to get the latest block/live data and

cardano-db-sync (https://github.com/input-output-hk/cardano-db-sync) or carp (https://github.com/dcSpark/carp)

to query the whole chain.

1

This is a relatively simple query against cardano-db-sync.

Your Answer

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

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