# README

Client for the blockchair.com API using GO.

![](https://847369752-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MkXMMUKnHh5eBC1WgyG%2F-MkfHV2WBl6RKXmUXNQG%2F-MkfJvBJSJsQ_pXQsJ6I%2FScreenshot%202021-09-06%20at%2019.35.54.png?alt=media\&token=ba86a579-042d-464d-bdf2-2da0be147ece)

[![BC-API version](https://camo.githubusercontent.com/0a2197d8059dd06f57fb5b41a36666d29dfcde709941cb2e802dd21e71f7b597/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f76657273696f6e2d76302e312e322d626c75653f7374796c653d666f722d7468652d6261646765266c6f676f3d6e6f6e65)](https://github.com/DiFronzo/blockchair/releases) [![go version](https://camo.githubusercontent.com/58e45131396897b5b6594051ba0314985cb5ef3eeefae1f80ee606b92d361d14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f474f2d312e31372b2d3030414444383f7374796c653d666f722d7468652d6261646765266c6f676f3d474f)](https://golang.org/) [![license](https://camo.githubusercontent.com/4063c583e768bf475969c3d8701fe6962706b61cf525dc7b4f1850ed5c061a20/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d7265643f7374796c653d666f722d7468652d6261646765266c6f676f3d6e6f6e65)](https://camo.githubusercontent.com/4063c583e768bf475969c3d8701fe6962706b61cf525dc7b4f1850ed5c061a20/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d7265643f7374796c653d666f722d7468652d6261646765266c6f676f3d6e6f6e65) [![code size](https://camo.githubusercontent.com/418104517418f4ce5070df29069617d0bf2a0dd07fb4bea659a1df2e8738e0e0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f646966726f6e7a6f2f626c6f636b63686169723f7374796c653d666f722d7468652d6261646765266c6f676f3d6e6f6e65)](https://camo.githubusercontent.com/418104517418f4ce5070df29069617d0bf2a0dd07fb4bea659a1df2e8738e0e0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f646966726f6e7a6f2f626c6f636b63686169723f7374796c653d666f722d7468652d6261646765266c6f676f3d6e6f6e65) [![GO report](https://camo.githubusercontent.com/33f4225b5cf8cdc56dcb9faf2b2a940ad9ff30c944f70794b811e052957ad620/68747470733a2f2f676f7265706f7274636172642e636f6d2f62616467652f6769746875622e636f6d2f446946726f6e7a6f2f626c6f636b63686169723f7374796c653d666f722d7468652d6261646765266c6f676f3d6e6f6e65) ](https://goreportcard.com/report/github.com/DiFronzo/blockchair)[![GoDoc](https://camo.githubusercontent.com/3990b1a9948c6803a0ed1e8f45b6e399f0cbe1691b35acf0d7001854b7981219/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f476f446f632d7265666572656e63652d626c75653f7374796c653d666f722d7468652d6261646765266c6f676f3d676f)](https://pkg.go.dev/github.com/DiFronzo/blockchair) [![GitHub Workflow Status](https://camo.githubusercontent.com/8fb1da014565948d09f7ac52ad1a8f6606af1084aa9a224b2ae202f986eb3a9a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f646966726f6e7a6f2f626c6f636b63686169722f54657374733f6c6f676f3d676974687562267374796c653d666f722d7468652d6261646765)](https://github.com/DiFronzo/blockchair/actions)<img src="https://847369752-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MkXMMUKnHh5eBC1WgyG%2F-MkfHV2WBl6RKXmUXNQG%2F-MkfHlpgKsTdeLQvM3qx%2FGITBOOK%20DOCUMENTATION.svg?alt=media&amp;token=7422eb46-9528-46f5-babc-3dae233e4e5a" alt="" data-size="original">&#x20;

## ⚡️ Quick start

First of all, [download](https://golang.org/) and install **GO**. Version `1.17` or higher is required.

Verify that the installation was successful by running the following command that should return the version number for GO.

```
go version
```

{% hint style="success" %}
If this command work, Go is successfully installed!
{% endhint %}

To quickly start using the module run the following command for installation.

```
go install github.com/DiFronzo/blockchair@latest
```

{% hint style="info" %}
For a detailed usage instructions, please refer to Dashboard [documentation](/dashboard).
{% endhint %}

That's all you need to know to start! 🎉

## ⚙️ Usage & Options

### **Dashboard:**

* [Transaction info](/dashboard/transaction-info)
* [Block info](/dashboard/block-info)
* [Address info](/dashboard/address-info)

For an example of usage see [here](https://github.com/DiFronzo/blockchair/blob/main/example/main.go).

### 🐳 Docker-way to quick start

UNDER CONSTRUCTION.

## ⭐️ Project assistance

If you want to say **thank you** or/and support active development of `blockchair`:

* Add a [GitHub Star](https://github.com/DiFronzo/blockchair) to the project.

## ⚠️ License

`Blockchair` is free and open-source software licensed under the [MIT](https://github.com/DiFronzo/blockchair/blob/main/LICENSE). This is not an offical release from [Blockchair](https://github.com/Blockchair). Use on your own risk.


# Dashboard

Retrieve information about various entities in a neat format from Blockchairs' databases


# Transaction info

Page about how to get transaction(s)

API documentation can be found for [Bitcoin-like](https://github.com/Blockchair/Blockchair.Support/blob/master/API_DOCUMENTATION_EN.md#-transaction-info) and [Ethereum](https://github.com/Blockchair/Blockchair.Support/blob/master/API_DOCUMENTATION_EN.md#-transaction-info-1) cryptocurrency on blockhairs website.

## Bitcoin-like cryptocurrency

### GetTransaction

GetTransaction fetches a Bitcoin-like transaction. The cryptocurrency supported, per 2021 September, are `bitcoin`, `bitcoin-cash`, `litecoin`, `bitcoin-sv`, `dogecoin`, `dash`, `groestlcoin`, `zcash`, `ecash`, `bitcoin/testnet`. Followed by the transaction hash (regex: `/^[0-9a-f]{64}$/i`), also known as txid.

#### Example usage of GetTransaction

```go
package main

import (
	"fmt"
	"log"
	"os"

	"github.com/DiFronzo/blockchair"
)

var clientID string

func init() {
	clientID = os.Getenv("API_KEY")
}

func main() {
	c := blockchair.New()
	c.APIKey = clientID // If you don't have an API key remove the lines about "clientID".
	resp, err := c.GetTransaction("bitcoin", "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16")
	if err != nil {
		log.Fatalln(err)
	}
	
	fmt.Println(resp)

}
```

{% hint style="warning" %}
**Request cost** is 1.
{% endhint %}

### GetTransactionAdv

GetTransactionAdv fetches a Bitcoin-like transaction and allowing options. The cryptocurrency supported, per 2021 September, are `bitcoin`, `bitcoin-cash`, `litecoin`, `bitcoin-sv`, `dogecoin`, `dash`, `groestlcoin`, `zcash`, `ecash`, `bitcoin/testnet`. Followed by the transaction hash (regex: `/^[0-9a-f]{64}$/i`), also known as txid. Lastly the wanted options in a map (for valid options see API doc. linked on top of the page).

#### Example usage of GetTransactionAdv

```go
package main

import (
	"fmt"
	"log"
	"os"

	"github.com/DiFronzo/blockchair"
)

var clientID string

func init() {
	clientID = os.Getenv("API_KEY")
}

func main() {
	c := blockchair.New()
	c.APIKey = clientID
	resp, err := c.GetTransactionAdv("bitcoin", "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16", map[string]string{"omni": "true"})
	if err != nil {
		log.Fatalln(err)
	}
	
	fmt.Println(resp)

}

```

{% hint style="warning" %}
**Request cost** is 1.
{% endhint %}

### GetTransactions

GetTransactions fetches mutliple Bitcoin-like transactions. The cryptocurrency supported, per 2021 September, are `bitcoin`, `bitcoin-cash`, `litecoin`, `bitcoin-sv`, `dogecoin`, `dash`, `groestlcoin`, `zcash`, `ecash`, `bitcoin/testnet`. Followed by the transaction hashes (regex: `/^[0-9a-f]{64}$/i`), also known as txid's.

```go
package main

import (
	"fmt"
	"log"
	"os"

	"github.com/DiFronzo/blockchair"
)

var clientID string

func init() {
	clientID = os.Getenv("API_KEY")
}

func main() {
	c := blockchair.New()
	c.APIKey = clientID
	resp, err := c.GetTransactions("bitcoin", []string{"ed232ffd13184a8ff682364d20d25575492fbc9f8904343308e2b68d71feda21", "ef4e4240cdca472910ba4e6d77102320cb866d378964f3e663d69fc5fbfc0cd9"})
	if err != nil {
		log.Fatalln(err)
	}
	
	fmt.Println(resp)
}
```

{% hint style="warning" %}
**Request cost** is $$0 < x \leq 10 \Rightarrow \lim\_{n \to x}1 + (0.1 \* (n - 1))$$&#x20;
{% endhint %}

### GetTransactionsAdv

GetTransactionsAdv fetches mutliple Bitcoin-like transactions and allowing options. The cryptocurrency supported, per 2021 September, are `bitcoin`, `bitcoin-cash`, `litecoin`, `bitcoin-sv`, `dogecoin`, `dash`, `groestlcoin`, `zcash`, `ecash`, `bitcoin/testnet`. Followed by the transaction hashes (regex: `/^[0-9a-f]{64}$/i`), also known as txid's.

```go
package main

import (
	"fmt"
	"log"
	"os"

	"github.com/DiFronzo/blockchair"
)

var clientID string

func init() {
	clientID = os.Getenv("API_KEY")
}

func main() {
	c := blockchair.New()
	c.APIKey = clientID
	resp, err := c.GetTransactionsAdv("bitcoin", []string{"ed232ffd13184a8ff682364d20d25575492fbc9f8904343308e2b68d71feda21", "ef4e4240cdca472910ba4e6d77102320cb866d378964f3e663d69fc5fbfc0cd9"}, map[string]string{"omni": "true"})
	if err != nil {
		log.Fatalln(err)
	}
	
	fmt.Println(resp)

}
```

{% hint style="warning" %}
**Request cost** is $$0 < x \leq 10 \Rightarrow \lim\_{n \to x}1 + (0.1 \* (n - 1))$$&#x20;
{% endhint %}

## Ethereum cryptocurrency

### GetTransactionEth

GetTransactionEth fetches an Ethereum transaction. The cryptocurrency supported, per 2021 September, are `ethereum`, `ethereum/testnet`. Followed by the transaction hash (regex: `/^0x[0-9a-f]{64}$/i`), also known as txid. **Request cost** is 1.

#### Example usage of GetTransactionEth

```go
package main

import (
	"fmt"
	"log"
	"os"

	"github.com/DiFronzo/blockchair"
)

var clientID string

func init() {
	clientID = os.Getenv("API_KEY")
}

func main() {
	c := blockchair.New()
	c.APIKey = clientID
	resp, err := c.GetTransactionEth("ethereum", "0xc132a422513e39038269e091847319a14029feb42c66bd1424c57dfc0e4f8d08")
	if err != nil {
		log.Fatalln(err)
	}

	fmt.Println(resp)
}

```

### GetTransactionEthAdv

GetTransactionEthAdv fetches an Ethereum transaction and allowing options. The cryptocurrency supported, per 2021 September, are `ethereum`, `ethereum/testnet`. Followed by the transaction hash (regex: `/^0x[0-9a-f]{64}$/i`), also known as txid. Lastly the wanted options in a map (for valid options see API doc. linked on top of the page). **Request cost** is 1.

```go
package main

import (
	"fmt"
	"log"
	"os"

	"github.com/DiFronzo/blockchair"
)

var clientID string

func init() {
	clientID = os.Getenv("API_KEY")
}

func main() {
	c := blockchair.New()
	c.APIKey = clientID
	resp, err := c.GetTransactionEthAdv("ethereum", "0xc132a422513e39038269e091847319a14029feb42c66bd1424c57dfc0e4f8d08", map[string]string{"erc_20": "true"})
	if err != nil {
		log.Fatalln(err)
	}
	
	fmt.Println(resp)

}

```


# Block info

Page about how to get block(es)

API documentation can be found for [Bitcoin-like ](https://github.com/Blockchair/Blockchair.Support/blob/master/API_DOCUMENTATION_EN.md#-block-info)and [Ethereum](https://github.com/Blockchair/Blockchair.Support/blob/master/API_DOCUMENTATION_EN.md#-block-info-1) cryptocurrency on blockhairs website.


# Address info

Page about how to get address(es)

API documentation can be found for [Bitcoin-like](https://github.com/Blockchair/Blockchair.Support/blob/master/API_DOCUMENTATION_EN.md#-address-and-extended-public-key-xpub-info) and [Ethereum](https://github.com/Blockchair/Blockchair.Support/blob/master/API_DOCUMENTATION_EN.md#-address-info) cryptocurrency on blockhairs website.


# Misc endpoints

Miscellaneous API endpoints


# Premium API usage stats

Special endpoint for Premium API users showing some stats on your API key usage.

## GetUsage

GetUsage fetches usage stats for API key. Require API key to be set.

```go
package main

import (
	"fmt"
	"log"
	"os"

	"github.com/DiFronzo/blockchair"
)

var clientID string

func init() {
	clientID = os.Getenv("API_KEY")
}

func main() {
	c := blockchair.New()
	c.APIKey = clientID
	resp, err := c.GetUsage()
	if err != nil {
		log.Fatalln(err)
	}
	
	fmt.Println(resp)

}
```

{% hint style="warning" %}
**Request cost** is 0.
{% endhint %}


# Q\&A

Questions and answers

## What is request cost?

Every API endpoint documentation has the "Request cost formula" section describing how the "cost" is calculated. For most API requests it's always 1. It's more than 1 in cases when you're requiring additional data (e.g. when you're requesting data on an Ethereum address, and you're also requesting its ERC-20 token balances).

{% hint style="info" %}
Example: **Request cost** is $$0 < x \leq 10 \Rightarrow \lim\_{n \to x}1 + (0.1 \* (n - 1))$$&#x20;

You want to send 10 addresses/blocks/transactions:

$$x = 10 \Rightarrow \lim\_{n \to 10}1 + (0.1 \* (10 - 1)) \Rightarrow 1 + (0.1 \* (10 - 1)) = 1.9$$&#x20;

You will have a request cost of **1.9**
{% endhint %}

## How many request are I limit to with the free tier?

You are limitied up to 1440 requests a day. With an API key you could do more than 1440 requests a day

## When do the request counter reset?

The daily request counter is reset at 00:00 UTC every day.


# Changelog

Log or record of all notable changes made to the project

## [V0.1.2 - Support for all Dashboard Endpoints API call](https://github.com/DiFronzo/blockchair/releases/tag/v0.1.2)

### Added

* Address (Bitcoin-like and Ethereum)
* Blocks (Bitcoin-like and Ethereum)
* Transaction (Bitcoin-like and Ethereum)
* xpub, zpub, and ypub
* Uncle (Ethereum)
* Omni Layer property (Bitcoin)
* ERC-20 token (Ethereum)
* ERC-20 token holder (Ethereum)
* Multichain address check (Bitcoin-like and Ethereum)
* Premium API


