Introduction to the TzKT API

Claude Barde
6 min readNov 20, 2023

--

Discover the power of the TzKT API for the Tezos blockchain

The Tezos blockchain is perfect for writing front-end applications as it exposes a lot of its data through its RPC endpoints. You have access to general data like accounts and operations, but also data from smart contract storages that are natively available, unlike other blockchains like Ethereum.

However, due to the nature of a blockchain, some information you may need is not directly available. For example, you would like to know the balance of an account a few days ago or get a list of all the elements in a big map.

Fortunately, there is a solution for these use cases: the TzKT API. The Baking Bad team provides a free API that you can use to get all sorts of data from the Tezos blockchain, in a fast and efficient manner.

In this article, you will learn more about the possibilities offered by the API.

Getting information about accounts

The TzKT API exposes a lot of information about the user accounts on Tezos.

Here are a few examples:

This endpoint takes an address as a parameter and returns various details associated with that address, for example, the public key, if the account is revealed or not, the balance, its delegation status, the number of tokens or transactions, etc.

This endpoint takes an address as a path parameter and optional query parameters to fine-tune the response, for example, the type of transaction or the target of the transactions.

It returns various details about the transactions, including their type, their timestamp, the block, etc.

This endpoint takes an address as a parameter and returns an integer representing the balance of the specified address.

This endpoint takes an address and a level as parameters and returns an integer representing the balance of the specified address at the provided level.

This endpoint takes an address as a path parameter and optional query parameters to fine-tune the response, for example, the interval between levels, the way to sort the results, the number of results, etc.

Getting information about big maps

It may be complicated to get data out of big maps because of the way they are serialized and stored on-chain. However, it becomes a lot easier to do it with the TzKT API.

Here are a few examples:

This endpoint takes a big map ID as a parameter and returns a JSON value providing information about the big map.

This endpoint takes a big map ID as a path parameter and optional query parameters to fine-tune the response, for example, if the key is active or not, the level at which the key was updated, the key or the value associated with that key, etc.

It returns various details about the key, including its ID, its hash, the value associated with the key, etc.

Getting information about blocks

Data stored in blocks can be valuable according to your use case. It is also quick and easy to get it with the TzKT API.

Here are a few examples:

This endpoint takes a block hash as a path parameter and optional query parameters to fine-tune the response, for example, if operations should be returned or the format of the response.

It returns various details about the block, including its level, its timestamp, the number of endorsements, the producer of the block, etc.

This endpoint takes a level as a path parameter and optional query parameters to fine-tune the response, for example, if operations should be returned or the format of the response.

It returns various details about the block, including its timestamp, the number of endorsements, the producer of the block, the paid fees, etc.

Getting information about contracts

You can also use the API to fetch different information about smart contracts.

Here are a few examples:

This endpoint takes a contract address as a parameter and returns various details about the contract, for example, its alias, its balance, its delegate or the number of transactions, etc.

This endpoint takes a contract address as a parameter and returns a string with the code of the specified contract.

This endpoint takes a contract address as a path parameter and optional query parameters to fine-tune the response, for example, if the response must include all the entrypoints or the format of the response.

It returns a list of entrypoints with various details, including the name, the parameter schema in JSON, Micheline or Michelson and whether the entrypoint is used or not.

This endpoint takes a contract address as a path parameter and optional query parameters to specify the format of the response.

It returns a list of views with various details, including the name of the view, the parameter type and the return type in different formats.

This endpoint takes a contract address as a path parameter and two optional query parameters, the level at which the storage was snapshot and the path to one element of the storage.

It returns a JSON string representing the storage and its values.

This endpoint takes a contract address as a path parameter and optional query parameters such as the tags of the big maps, the way to sort the result, the number of results and the format of the result.

It returns an array of JSON values representing each big map that include various details, for example, the big map pointer, the path to the big map, whether the big map is active or not, the number of keys, the types for the keys and values, etc.

Getting information about operations

A back-end application could be interested in accessing operation data from the Tezos blockchain. The TzKT API also helps with that.

Here are a few examples:

This endpoint takes an operation hash as a parameter and returns a list of operations with various details, for example, the operation type, the level, the timestamp, the block, etc.

This endpoint takes an operation hash as a parameter and returns true if the operation was applied, false if it failed and null if it doesn’t exist.

This endpoint takes different query parameters to filter the results, such as the initiator of the transaction, the sender, the target, the amount, the parameter, etc.

It returns a list of transaction operations with various details about each operation, including its type, its level, its timestamp, its hash, etc.

This endpoint takes an operation hash as a parameter and returns a list of transaction operations where each operation is a JSON value that includes various details, for example, the operation type, the level, the timestamp, the block, etc.

Getting information about tokens

One of my favourite features of the API is how easy it is to get data about tokens. Instead of fetching and parsing the storage of multiple contracts to figure out which tokens a certain account holds, you can use a single HTTP request with the TzKT API, among other useful features.

Here are a few examples:

This endpoint takes different query parameters, for example, a contract address, a token ID, a level or a token standard and returns an integer representing the number of tokens.

This endpoint takes different query parameters, for example, a contract or account address, a token ID, a level or a token standard.

It returns a list of balances where each result provides various details, such as the associated account, the token, the balance itself, etc.

This endpoint takes different query parameters, for example, a contract address, a token ID, the address of the sender or the recipient, the transferred amount, etc.

It returns a list of transfers where each result provides various details such as the level, information about the token, the address of the sender and the recipient, the amount, etc.

Getting information about events

To finish, the TzKT API provides also information about different events emitted by smart contracts.

Here is an example:

This endpoint takes different query parameters, for example, the level for the events, the contract the events originated from, the event tag, etc.

It returns a list of events where each result provides various details about the event, such as the level, the timestamp, the contract, the payload, the type, etc.

Conclusion

The TzKT API emerges as an invaluable tool for developers working with the Tezos blockchain.

Its comprehensive coverage of diverse blockchain aspects, including accounts, big maps, contracts, operations, tokens, and events, enables a more efficient and streamlined way to access and manipulate blockchain data. This API not only simplifies the retrieval of complex data types but also addresses specific needs such as historical account balances and detailed smart contract interactions.

With its user-friendly endpoints and the extensive documentation available, the TzKT API empowers developers to build robust and feature-rich applications on the Tezos blockchain with greater ease and precision.

Its integration into development workflows represents a significant step forward in harnessing the full potential of blockchain technology, particularly for applications requiring a deep and dynamic interaction with blockchain data.

Links

The TzKT API docs -> https://api.tzkt.io/

--

--

Claude Barde

Self-taught developer interested in web3, smart contracts and functional programming