Cover Image for Cardano APIs: Staking, Transactions, Blocks, and More

Cardano APIs: Staking, Transactions, Blocks, and More

Cardano
Staking
Transactions
Transfers
Blocks

Blockchain technology has gone beyond its initial purpose of cryptocurrencies by moving into advanced aspects such as decentralized applications, protocols, and smart contracts.

Cardano, a third-generation blockchain platform, has rapidly emerged as a prominent player in this space. Cardano APIs are widely used by developers to harness data and build applications with the Cardano blockchain. For example, Bitquery provides a host of APIs that developers can use for interacting with the Cardano chain.

In this article, we'll explore many Cardano APIs, and how you can leverage their capabilities for integrating them with your own applications.

What is Cardano?

Founded in 2015 (but implemented in 2017) by Charles Hoskinson, one of the co-founders of Ethereum, Cardano is a rapidly growing blockchain platform that aims to provide a secure and scalable infrastructure.

It is a proof-of-stake decentralized blockchain, as opposed to other blockchains, which are proof-of-work blockchains. Cardano uses a research-driven approach and is a sustainable alternative because of its energy-efficiency. The native cryptocurrency of Cardano is ADA (named after Augusta Ada King, Countess of Lovelace, considered as the pioneer of computer programming).

Cardano's architecture is multi-layered and consists of:

  • Settlement or accounting layer (for ADA transactions)
  • Computation layer (for running smart contracts and dApps)

Cardono’s consensus mechanism is called Ouroboros and it uses mathematical principles to provide a highly secure and safe network.

How does Cardano help developers?

Key advantages of Cardano are:

  • Energy efficiency
  • Quicker and scalable transactions
  • Peer-reviewed research

Cardano facilitates developers to create other decentralized applications or dApps, tokens, smart contracts, use cases for banking and finance, and more on the fastest-growing network.

One of the great features of Cardano is its security and stability. This means the developers can be sure that their code will be executed correctly, as intended.

Overview of Cardano APIs

The Cardano API acts as a bridge between developers and the Cardano blockchain and provides a set of tools and functionalities for building and integrating applications with the chain.

There are several APIs you can use to get data on Cardano:

  • Cardano Explorer API: The Cardano Explorer API provides comprehensive data on Cardano blockchain. There are many providers of Cardano Explorer APIs. Bitquery is one of the leading providers with an easy-to-use interface for obtaining indexed data from the Cardano blockchain.

  • Cardano Node API: Retrieves real-time data from the Cardano blockchain. Developers can use the Node API to query information about blocks, transactions, addresses, and more.

  • Cardano Wallet API: Simplifies the integration of wallet functionalities into dApps. Developers can use this API to create and manage wallets, check balances, send and receive transactions, and explore transaction history.

  • Metadata API: The Metadata API enables developers to attach metadata to transactions, making it possible to include relevant information such as text, links, or even media files.

To learn more about Cardano APIs, refer to the Cardano developer documentation and Cardano API documentation.

Cardano Blockchain Explorer API - Overview of Cardano

To view key statistics of Cardano on chain data, use the Bitquery Explorer. It provides an easy user interface for retrieving data including transactions, addresses, blocks, and more. Bitquery also has an in-built GraphQL IDE, which you can use to write custom queries.

Home page of Bitquery Cardano Explorer

Tip: If you’re new to building queries, simply click on the Get API button on the bottom right of the screen to get your query. For example, to get the query for an overview of transactions on the chain, click the Get API button.

The query is displayed in the GraphQL IDE as follows:

{
    cardano(network: cardano) {
        blocks(
            options: {desc: "height", limit: 10, offset: 0}
            time: {since: "2023-11-30T06:10:00Z", till: "2023-11-30T06:17:00Z"}
        ) {
            timestamp {
                time(format: "%Y-%m-%d %H:%M:%S")
            }
            height
            epoch
            transactionCount
            blockSize
        }
    }
}

Let’s discuss how you can leverage other Bitquery APIs to obtain Cardano on chain data.

Cardano Blocks API

Retrieving Blocks Data

The Cardano Blocks API by Bitquery allows to you retrieve data on all the blocks or a specific block on the Cardano chain.

To retrieve specific block data, either use the Bitquery Explorer or try building the query in IDE. Let’s write the query to obtain specific block data, say 9612373.

Open the query in IDE and replace height with the block number as shown here. Replace network variable with “cardano” as shown.

query  {
    cardano(network: cardano) {
        blocks(height: {is: 9612373}) {
            timestamp {
                time(format: "%Y-%m-%d %H:%M:%S")
            }
            blockHash
            blockSize
            blockVersion
            transactionCount
            epoch
            opCert
            slot
            slotInEpoch
            slotLeaderDescription
            slotLeaderHash
            vrfKey
        }
    }
}

Cardano Transactions API

You can retrieve all the transactions done on Cardano blockchain easily from the Cardano Transactions API. This includes the value of ADA traded during a specific period, number of mints, fees paid for the transaction, inputs and outputs for the transaction and more.

Obtaining Recent Transactions Data

Let’s try to get all transactions done on the chain on 29th November 2023.

Open IDE and write the query as shown. Add the above date for the date parameter and select the network as Cardano.

{
    cardano(network: cardano) {
        transactions(options: {limit: 10}, date: {is: "2023-11-29"}) {
            block {
                timestamp {
                    time(format: "%Y-%m-%d %H:%M:%S")
                }
                height
            }
            inputValue
            input_value_usd: inputValue(in: USD)
            feeValue
            fee_value_usd: feeValue(in: USD)
            mintCount
            withdrawalValue
            withdrawalCount
            outputValue
        }
    }
}

This gives you data on the chain for the selected date and provides information on fees paid, number of mints, number of withdrawals, input and output values of the transaction as specified in the query.

Obtaining Outbound Transfers Data

You can also check for outbound transfers from a specific address (specify the address in the address variable) to know the amount of ADA transfers. Open this query in IDE and set the value in USD to find out the number of outbound transfers and their value on a given date. In this case, the address is addr1v96fnqhewa22ytrtc694qd0rzst24krwd03etjul2taaxdsshxzqx.

{
    cardano(network: cardano) {
        inputs(
            currency: {is: "ADA"}
            date: {since: "2023-11-30", till: "2023-12-19"}
            inputAddress: {is: "addr1v96fnqhewa22ytrtc694qd0rzst24krwd03etjul2taaxdsshxzqx"}
            options: {asc: "date.date"}
        ) {
            date: date {
                date(format: "%Y-%m-%d")
            }
            count: countBigInt(uniq: transactions)
            value(in: USD)
        }
    }
}

This helps developers to understand the transaction history of a specific Cardano address along with its blocks. Similarly, you can build queries for transaction inflows and money flows.

Cardano Balances API

Retrieving Balances Data

To check for transaction balances on the chain, add the parameter “balance” from the IDE schema to your query. For example, to check for unspent amounts, use the following query in IDE.

{
    cardano(network: cardano) {
        inputs(
            currency: {is: "ADA"}
            inputAddress: {is: "addr1v96fnqhewa22ytrtc694qd0rzst24krwd03etjul2taaxdsshxzqx"}
        ) {
            count
            value
            value_usd: value(in: USD)
            min_date: minimum(of: date)
            max_date: maximum(of: date)
        }
        outputs(
            currency: {is: "ADA"}
            outputAddress: {is: "addr1v96fnqhewa22ytrtc694qd0rzst24krwd03etjul2taaxdsshxzqx"}
        ) {
            count
            value
            value_usd: value(in: USD)
            min_date: minimum(of: date)
            max_date: maximum(of: date)
        }
        addressStats(
            address: {is: "addr1v96fnqhewa22ytrtc694qd0rzst24krwd03etjul2taaxdsshxzqx"}
        ) {
            address {
                balance(in: USD)
            }
        }
    }
}

Cardano Coinpath API

Tracking Funds

This API helps in tracing and tracking funds between addresses. Bitquery provides a visual representation of the same.

However, if you want to use this query in your application, you can build the query in IDE.

Let’s say you want to track funds (both inflows and outflows) from Address 1 (addr1q8hq60cyqg68aqfzs9geq084yj0tvvpm7rnckn6gsf3ahyrwak0antyvs6lyd7ymqg2zp6q8999vsdadmpm70x93f8msd7uwux).

Open the query in IDE and replace the variable address with the one given above.

{
    cardano(network: cardano) {
        inbound: coinpath(
            currency: {is: "ADA"}
            initialAddress: {is: "addr1q8hq60cyqg68aqfzs9geq084yj0tvvpm7rnckn6gsf3ahyrwak0antyvs6lyd7ymqg2zp6q8999vsdadmpm70x93f8msd7uwux"}
            depth: {lteq: 2}
            options: {direction: inbound, asc: "depth", desc: "amount", limitBy: {each: "depth", limit: 2}}
            date: {since: "2023-11-30", till: "2023-12-18"}
        ) {
            sender {
                address
                annotation
            }
            receiver {
                address
                annotation
            }
            amount
            depth
            count
        }
        outbound: coinpath(
            currency: {is: "ADA"}
            initialAddress: {is: "addr1q8hq60cyqg68aqfzs9geq084yj0tvvpm7rnckn6gsf3ahyrwak0antyvs6lyd7ymqg2zp6q8999vsdadmpm70x93f8msd7uwux"}
            depth: {lteq: 2}
            options: {asc: "depth", desc: "amount", limitBy: {each: "depth", limit: 2}}
            date: {since: "2023-11-30", till: "2023-12-18"}
        ) {
            sender {
                address
                annotation
            }
            receiver {
                address
                annotation
            }
            amount
            depth
            count
        }
    }
}

You can edit this to exclude outbound if you want information only on inflows to the address and vice versa.

Cardano Staking API

Getting Staking Rewards Information

Cardano is a proof-of stake system, where users can hold crypto (ADA, in this case) to earn rewards. It involves nodes that can open blocks on Cardano to hold and stake ADA over a long period. To get data on which address or node is using the staking function and the amount of rewards earned, use the Cardano Staking API.

For example, to find out the staking information for our address addr1q8hq60cyqg68aqfzs9geq084yj0tvvpm7rnckn6gsf3ahyrwak0antyvs6lyd7ymqg2zp6q8999vsdadmpm70x93f8msd7uwux, use the following query in IDE.

{
    cardano {
        address(
            address: {is: "addr1q8hq60cyqg68aqfzs9geq084yj0tvvpm7rnckn6gsf3ahyrwak0antyvs6lyd7ymqg2zp6q8999vsdadmpm70x93f8msd7uwux"}
        ) {
            address {
                address
            }
            staking {
                rewardsAmount
                stakedAmount
            }
        }
    }
}

**Cardano Mint API **

Retrieving Number of Tokens Minted on a Block

Mints are events of new tokens created on blocks. This API helps obtain data on the number of tokens minted, the block where the tokens were minted, the transaction that contained the mints, and the currency transacted.

For example, let’s find out the number of tokens minted in the block, 9613382. To do so, open this query in IDE and specify the height variable as 9613382.

{
  cardano {
    address(
        address: {is: "addr1q8hq60cyqg68aqfzs9geq084yj0tvvpm7rnckn6gsf3ahyrwak0antyvs6lyd7ymqg2zp6q8999vsdadmpm70x93f8msd7uwux"}
    ) {
        address {
            address
        }
        staking {
            rewardsAmount
            stakedAmount
        }
    }
  }
}

Cardano Wallet APIs

Address API - Getting Wallet Details

To get data on Cardano wallets, use the Cardano Address API from Bitquery. Open the query in IDE. Specify the address for which you want the wallet details, as given here. The API returns information on the wallet balance and staking rewards information.

{
    cardano(network: cardano) {
        address(
            address: {is: "addr1q8wp4tc65hgvvff0lg2dgp8dnd2hy5u4vyz9mgk8qancwmtdf8tun55syv9gvfd0dgdhx02vlyg6dp56up92a5l9qxhs9nhrfy"}
        ) {
            address {
                address
                annotation
            }
            balance {
                value
                currency {
                    name
                    decimals
                    address
                    tokenType
                    symbol
                    tokenId
                }
            }
            staking {
                controlledTotalStake
                rewardsAmount
                rewardsAvailable
                stakedAmount
                stakedAmountWithRewards
                withdrawnAmount
                address {
                    address
                    annotation
                }
            }
        }
    }
}

AddressStats API - Getting Wallet Inflows/Outflows Data

Use this API to get more details about wallets - including inflows, outflows, and other transactional details. Specify an address to find out details of its associated wallet as given here. This API also provides details on unique receivers and senders.

{
    cardano(network: cardano) {
        addressStats(
            address: {is: "addr1q8wp4tc65hgvvff0lg2dgp8dnd2hy5u4vyz9mgk8qancwmtdf8tun55syv9gvfd0dgdhx02vlyg6dp56up92a5l9qxhs9nhrfy"}
        ) {
            address {
                address
                annotation
                balance
                firstActive {
                    time
                }
                inboundTransactions
                inflows
                lastActive {
                    time
                }
                outboundTransactions
                outflows
                uniqueDaysWithTransfers
                uniqueReceivers
                uniqueSenders
            }
        }
    }
}

Building with Cardano API

Developers looking to harness the power of the Cardano blockchain should keep the following in mind when integrating Cardano API into their applications.

Whether querying for blockchain information or managing wallets, selecting the right Cardano API endpoints is crucial for efficient and effective development.

Always refer to the Cardano API documentation, which is a valuable resource for developers. The documentation provides detailed information about available endpoints, request parameters, and response formats.

Additionally, engaging with the Cardano community can offer insights, best practices, and solutions to common challenges.

About Bitquery

Bitquery is your comprehensive toolkit designed with developers in mind, simplifying blockchain data access. Our products offer practical advantages and flexibility.

  • APIs - Explore API: Easily retrieve precise real-time and historical data for over 40 blockchains using GraphQL. Seamlessly integrate blockchain data into your applications, making data-driven decisions effortless.

  • Coinpath® - Try Coinpath: Streamline compliance and crypto investigations by tracing money movements across 40+ blockchains. Gain insights for efficient decision-making.

  • Data in Cloud - Try Demo Bucket: Access indexed blockchain data cost-effectively and at scale for your data pipeline. We currently support Ethereum, BSC, Solana, with more blockchains on the horizon, simplifying your data access.

  • Explorer - Try Explorer: Discover an intuitive platform for exploring data from 40+ blockchains. Visualize data, generate queries, and integrate effortlessly into your applications.

Bitquery empowers developers with straightforward blockchain data tools. If you have questions or need assistance, connect with us on our Telegram channel or via email at sales@bitquery.io. Stay updated on the latest in cryptocurrency by subscribing to our newsletter below.

This article has been written by guest writer Aparna Sridhar

Subscribe to our newsletter

Subscribe and never miss any updates related to our APIs, new developments & latest news etc. Our newsletter is sent once a week on Monday.