### Get Bitcoin Hashrate Dashboard Example Source: https://github.com/blockchair/blockchair.support/blob/master/API.md Example of retrieving the estimated daily hashrate for Bitcoin. ```HTTP https://api.blockchair.com/bitcoin/dashboards/hashrate ``` -------------------------------- ### Curl Command Example: Get Ethereum Account Balance Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/INDEX.md Demonstrates how to get an Ethereum account's balance using a curl command. Useful for quick balance checks. ```bash curl "https://api.blockchair.com/ethereum/dash.php?address=YOUR_ETHEREUM_ADDRESS" ``` -------------------------------- ### Example: Get 2nd Page of Richest Addresses Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/api-reference/infinitable-queries.md This example demonstrates fetching the second page of results for the richest Bitcoin addresses, using a limit of 100 and an offset of 100. ```url https://api.blockchair.com/bitcoin/addresses?s=balance(desc)&limit=100&offset=100 ``` -------------------------------- ### Usage Examples Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/00-START-HERE.txt Provides over 25 code examples in JavaScript and Python for common tasks such as Bitcoin block queries, transaction lookups, address balance checking, and Ethereum/ERC-20 operations. ```APIDOC ## Usage Examples This section offers practical code examples to help you integrate with the Blockchair API quickly and efficiently. ### Languages: * **JavaScript** * **Python** ### Example Scenarios: * **Bitcoin Block Queries**: Fetching details of specific Bitcoin blocks. * **Transaction Lookups**: Retrieving information about individual transactions. * **Address Balance Checking**: Querying the current balance of a given address. * **Ethereum and ERC-20 Operations**: Interacting with Ethereum data and ERC-20 token transfers. * **Market Analysis Patterns**: Examples demonstrating how to derive market insights. * **Retry Logic and Error Handling**: Demonstrations of implementing robust error handling. With over 25 examples, `api-reference/usage-examples.md` provides a solid foundation for building applications using the Blockchair API. ``` -------------------------------- ### Infinitable Endpoint Examples Source: https://github.com/blockchair/blockchair.support/blob/master/API_DOCUMENTATION_EN.md Examples demonstrating how to use the Infinitable endpoints for data aggregation and filtering. ```APIDOC ## GET /:coin/blocks ### Description Retrieves aggregated reward data for blocks. ### Method GET ### Endpoint `https://api.blockchair.com/bitcoin/blocks?a=sum(reward)` ### Parameters #### Query Parameters - **a** (string) - Required - Aggregation function to apply (e.g., `sum(reward)`) ### Response #### Success Response (200) - **data** (object) - Contains the aggregated results. #### Response Example ```json { "data": { "sum(reward)": "12345.678" } } ``` ## GET /:coin/transactions ### Description Retrieves aggregated output total for transactions, filtered by coinbase transactions. ### Method GET ### Endpoint `https://api.blockchair.com/bitcoin/transactions?a=sum(output_total)&q=is_coinbase(true)` ### Parameters #### Query Parameters - **a** (string) - Required - Aggregation function to apply (e.g., `sum(output_total)`) - **q** (string) - Required - Query filter (e.g., `is_coinbase(true)`) ### Response #### Success Response (200) - **data** (object) - Contains the aggregated results. #### Response Example ```json { "data": { "sum(output_total)": "98765.432" } } ``` ## GET /:coin/outputs ### Description Retrieves aggregated value for outputs, filtered by coinbase outputs. ### Method GET ### Endpoint `https://api.blockchair.com/bitcoin/outputs?a=sum(value)&q=is_from_coinbase(true)` ### Parameters #### Query Parameters - **a** (string) - Required - Aggregation function to apply (e.g., `sum(value)`) - **q** (string) - Required - Query filter (e.g., `is_from_coinbase(true)`) ### Response #### Success Response (200) - **data** (object) - Contains the aggregated results. #### Response Example ```json { "data": { "sum(value)": "54321.098" } } ``` ``` -------------------------------- ### Premium API Usage Stats Example Source: https://github.com/blockchair/blockchair.support/blob/master/API_DOCUMENTATION_EN.md This example shows how to request usage statistics for your Premium API key. The response includes details about key validity, request limits, and current usage. ```json { "data": { "valid_until": "2020-01-01 00:00:00", "max_requests_per_day": 100000, "requests_today": 50000 }, "context": { ... } } ``` -------------------------------- ### Request Cost Calculation Example Source: https://github.com/blockchair/blockchair.support/blob/master/API_DOCUMENTATION_EN.md This example demonstrates how the request cost is calculated by summing the costs of individual blockchain endpoint calls. It shows the breakdown for Bitcoin, Ethereum, and Litecoin. ```text The total cost is the same as if you'd use `dashboards/addresses` endpoints for the requested blockchains separately with the `?transaction_details=true` option enabled. In the example, the cost is `5.1`, and it's calculated as the sum of using the following endpoints: * `https://api.blockchair.com/bitcoin/dashboards/addresses/1JADsmDFX9d2TXis63S9F9L8eDAXwJmnWE,1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa?transaction_details=true` (cost: `2.1`) * `https://api.blockchair.com/ethereum/dashboards/address/0x19DdD94B94D3c68385c897846AB44Ac99DBFAe0f` (cost: `1`) * `https://api.blockchair.com/litecoin/dashboards/addresses/LNAifc8nfjtDJ8azRPiancbZSBftPzhfzb?transaction_details=true` (cost: `2`) ``` -------------------------------- ### Example API Request and Response Source: https://github.com/blockchair/blockchair.support/blob/master/API_DOCUMENTATION_EN.md This snippet shows an example of how to query the 'calls' table and the structure of the JSON response. ```APIDOC ## Example API Request and Response ### Request Example This example demonstrates a request to the Blockchair API to retrieve calls, excluding synthetic coinbase calls, with a limit of 1. ```http GET https://api.blockchair.com/ethereum/calls?q=not,type(synthetic_coinbase)&limit=1 ``` ### Response Example This is an example of the JSON response structure for a successful query to the 'calls' endpoint. ```json { "data": [ { "block_id": 8792132, "transaction_id": 8792132000050, "transaction_hash": "0x9e3a13bfc5313245de7142b7ec13b80123188d9ae4cce797a44b9b426864d1ca", "index": "0", "depth": 0, "date": "2019-10-22", "time": "2019-10-22 19:30:03", "failed": false, "fail_reason": null, "type": "call", "sender": "0xe475e906b74806c333fbb1b087e523496d8c4cb7", "recipient": "0x3143ec5a285adfb248c9e4de934ee735d4b7d734", "child_call_count": 0, "value": "0", "value_usd": 0, "transferred": true, "input_hex": "a9059cbb00000000000000000000000023ea8008420c4355570f9915b5fe39dc278540d3000000000000000000000000000000000000000000000000000000003b9aca00", "output_hex": "0000000000000000000000000000000000000000000000000000000000000001" } ], "context": { "code": 200, "limit": 1, "offset": 0, "rows": 1, "total_rows": 1422927649, "state": 8792138, "state_layer_2": 8792127, ... } } ``` ``` -------------------------------- ### Mixin API Snapshots Endpoint Examples Source: https://github.com/blockchair/blockchair.support/blob/master/API_DOCUMENTATION_EN.md These examples demonstrate how to access the raw snapshots data from the Mixin API. The 'snapshots' table supports offset and topology-based queries. ```bash https://api.blockchair.com/mixin/raw/snapshots ``` ```bash https://api.blockchair.com/mixin/raw/snapshots?q=topology(..18629737)&offset=10 ``` ```bash https://api.blockchair.com/mixin/raw/snapshots?s=topology(asc) ``` -------------------------------- ### Common Query Examples Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/api-reference/infinitable-queries.md Provides examples of common API queries, including rich lists, large transactions, block statistics, contract interactions, SegWit adoption, and average transaction fee trends. ```APIDOC ## Common Query Examples ### Rich List (Top 100 Bitcoin Addresses) ``` https://api.blockchair.com/bitcoin/addresses?s=balance(desc)&limit=100 ``` ### Large Transactions (Last 24h) ``` https://api.blockchair.com/bitcoin/transactions?q=time(~P1D)&s=input_total(desc)&limit=50 ``` ### Block Statistics (Daily) ``` https://api.blockchair.com/bitcoin/blocks?a=date,count(),avg(size),sum(fee_total)&s=date(asc) ``` ### Ethereum Contract Interactions ``` https://api.blockchair.com/ethereum/calls?q=to(0x...)&s=block_id(desc)&limit=100 ``` ### SegWit Adoption (Percentage over time) ``` https://api.blockchair.com/bitcoin/transactions?a=date,f(sum(case when has_witness=1 then 1 else 0 end)*100/count()) ``` ### Average Transaction Fee Trend ``` https://api.blockchair.com/bitcoin/transactions?a=week,avg(fee)&s=week(asc) ``` ``` -------------------------------- ### Fun Example Queries Source: https://github.com/blockchair/blockchair.support/blob/master/API_DOCUMENTATION_EN.md These requests demonstrate how to achieve the same result using different infinitable endpoints and aggregation functions. ```http https://api.blockchair.com/bitcoin/blocks?a=sum(reward) ``` ```http https://api.blockchair.com/bitcoin/transactions?a=sum(output_total)&q=is_coinbase(true) ``` ```http https://api.blockchair.com/bitcoin/outputs?a=sum(value)&q=is_from_coinbase(true) ``` -------------------------------- ### Curl Command Example: Get Latest Bitcoin Block Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/INDEX.md Example of how to fetch the latest Bitcoin block using a curl command. Demonstrates basic API interaction. ```bash curl "https://api.blockchair.com/bitcoin/latest" ``` -------------------------------- ### Example JSON Output for Release Monitor Source: https://github.com/blockchair/blockchair.support/blob/master/API_DOCUMENTATION_EN.md This is a sample JSON output for the /tools/releases endpoint, showing the structure of the 'data' array with release information and the 'context' object containing 'latest_update' and 'supported_chains'. ```json { "data": [ { "chain": "bitcoin-sv", "version": "Bitcoin SV v1.0.1", "time": "2020-01-28 11:35:26", "link": "https://github.com/bitcoin-sv/bitcoin-sv/releases/tag/v1.0.1" }, { "chain": "dash", "version": "Dash Core v0.15.0.0-rc2", "time": "2020-01-27 20:12:45", "link": "https://github.com/dashpay/dash/releases/tag/v0.15.0.0-rc2" }, { "chain": "groestlcoin", "version": "Groestlcoin Core v2.18.2", "time": "2020-01-25 12:53:41", "link": "https://github.com/Groestlcoin/groestlcoin/releases/tag/v2.18.2" }, { "chain": "stellar", "version": "Stellar Core v12.3.0rc2", "time": "2020-01-24 04:57:51", "link": "https://github.com/stellar/stellar-core/releases/tag/v12.3.0rc2" }, { "chain": "stellar", "version": "Stellar Core v12.3.0rc1", "time": "2020-01-22 23:54:01", "link": "https://github.com/stellar/stellar-core/releases/tag/v12.3.0rc1" }, { "chain": "bitcoin-cash", "version": "Bitcoin ABC v0.20.11", "time": "2020-01-21 21:46:10", "link": "https://github.com/Bitcoin-ABC/bitcoin-abc/releases/tag/v0.20.11" }, { "chain": "ethereum", "version": "Geth v1.9.10", "time": "2020-01-20 10:36:41", "link": "https://github.com/ethereum/go-ethereum/releases/tag/v1.9.10" }, ... ], "context": { "code": 200, "latest_update": "2021-03-12 10:36:16", "supported_chains": { "bitcoin": "Bitcoin Core", "bitcoin-abc": "Bitcoin ABC", "bitcoin-cash": "Bitcoin Cash Node", "ethereum": "Geth", "litecoin": "Litecoin Core", "bitcoin-sv": "Bitcoin SV", "dogecoin": "Dogecoin Core", "dash": "Dash Core", "ripple": "rippled", "groestlcoin": "Groestlcoin Core", "stellar": "Stellar Core", "monero": "Monero", "cardano": "Cardano Node", "zcash": "Zcash", "mixin": "Mixin", "eos": "EOSIO" }, ... } } ``` -------------------------------- ### Ethereum Address Dashboard with ERC-20 and USD Values Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/configuration.md Example for fetching Ethereum address data, including approximate ERC-20 balances and their corresponding USD valuations. ```bash # Get ERC-20 balances with USD values https://api.blockchair.com/ethereum/dashboards/address/0x...?erc_20=approximate&assets_in_usd=true ``` -------------------------------- ### Infinitable Queries Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/00-START-HERE.txt Learn how to perform complex queries using a SQL-like syntax, with documentation on 12 queryable tables, 10+ aggregation functions, and over 20 practical query examples. ```APIDOC ## Infinitable Queries The Blockchair API supports advanced querying capabilities using a SQL-like syntax, allowing for complex data retrieval and analysis. ### Query Syntax: * **SQL-like**: Supports filters, aggregation, and sorting. * **Queryable Tables**: Documentation covers 12 different tables you can query. * **Aggregation Functions**: Over 10 aggregation functions are available, with examples provided. ### Examples: * The `api-reference/infinitable-queries.md` file includes more than 20 practical query examples to illustrate usage. This feature enables powerful data exploration beyond simple endpoint calls. For detailed syntax and examples, consult `api-reference/infinitable-queries.md`. ``` -------------------------------- ### Get Latest Bitcoin Block Stats Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/api-reference/usage-examples.md Retrieve the latest block height and timestamp for the Bitcoin blockchain using a simple GET request. This example shows how to parse the response in JavaScript. ```bash curl https://api.blockchair.com/bitcoin/stats ``` ```javascript const response = await fetch('https://api.blockchair.com/bitcoin/stats'); const data = await response.json(); const latestBlock = data.context.state; const blockTime = data.data.best_block_time; console.log(`Latest block: ${latestBlock} at ${blockTime}`); ``` -------------------------------- ### Fetch Bitcoin Address Balance (Python) Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/00-START-HERE.txt Python example to fetch the balance of a Bitcoin address. Uses the 'requests' library. Replace YOUR_KEY with your actual API key. ```python import requests api_key = "YOUR_KEY" address = "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa" url = f"https://api.blockchair.com/bitcoin/dash/address/{address}?key={api_key}" response = requests.get(url) data = response.json() if response.status_code == 200: print(f"Balance for {address}: {data['data']['address']['balance']}") else: print(f"Error: {response.status_code} - {data['error']['message']}") ``` -------------------------------- ### Curl Command Example: Get Bitcoin Transaction Details Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/INDEX.md Example of fetching Bitcoin transaction details using a curl command. Useful for quick checks without writing code. ```bash curl "https://api.blockchair.com/bitcoin/transaction/YOUR_TX_ID" ``` -------------------------------- ### Count Aggregation Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/api-reference/infinitable-queries.md Use `count()` to get the total number of items. Example shows total blocks in Bitcoin. ```api ?a=count() ``` ```url https://api.blockchair.com/bitcoin/blocks?a=count() ``` -------------------------------- ### Infinitable Query Syntax Examples Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/configuration.md Demonstrates the flexible query syntax for filtering data using column conditions, intervals, and logical AND operations. ```bash ?q=column(value) ``` ```bash ?q=column(min..max) ``` ```bash ?q=column(~interval) # e.g., time(~P1D) for last 24h ``` ```bash ?q=condition1,condition2 # AND logic ``` -------------------------------- ### Constructing a Query with Filters, Sorting, and Limit Source: https://github.com/blockchair/blockchair.support/blob/master/API_DOCUMENTATION_EN.md Example of building a complex query for the bitcoin/blocks table, filtering by time and miner, sorting by size, and limiting results. ```url https://api.blockchair.com/bitcoin/blocks?q=time(2019-01),guessed_miner(AntPool)&s=size(desc)&limit=1 ``` -------------------------------- ### Get Latest Bitcoin Block (JavaScript) Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/INDEX.md Retrieve the latest Bitcoin block information. This is a common starting point for monitoring blockchain activity. ```javascript async function getLatestBlock() { const response = await fetch('https://api.blockchair.com/bitcoin/latest'); const data = await response.json(); console.log('Latest Block:', data.data.latest_block.hash); } ``` -------------------------------- ### Configuration and Parameters Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/00-START-HERE.txt This section covers API key acquisition, usage tiers (free and premium), and details over 30 request parameters that can be used to customize queries. It also explains response format options and caching behavior. ```APIDOC ## Configuration and Request Parameters This section details how to configure your API access and leverage the various request parameters available to tailor your data retrieval. ### API Key and Tiers: * **Authentication**: API key is provided in the query string (e.g., `?key=YOUR_KEY`). * **Free Tier**: Allows up to 1440 requests per day. * **Premium Tier**: Offers higher limits based on your subscription plan. ### Request Parameters: The API supports over 30 request parameters to refine your queries. These parameters allow for customization of the data returned, filtering, and other options. Refer to the `configuration.md` file for a complete list and explanation of all available request parameters. ### Response Format: * **Default**: JSON. * **Export Options**: CSV and TSV formats are available via specific parameters. ### Caching: * **Stats**: Cached for 60 seconds. * **Dashboard**: Cached for 30 seconds. * **Infinitable Queries**: Cached for 10 seconds. Detailed information on configuration and parameters can be found in `configuration.md`. ``` -------------------------------- ### Get Block Information by Hash (Implied) Source: https://github.com/blockchair/blockchair.support/blob/master/API_DOCUMENTATION_EN.md While not explicitly shown with a hash example, the API supports retrieving block information using a block hash. ```HTTP https://api.blockchair.com/bitcoin/dashboards/block/9999999 ``` -------------------------------- ### Get Ethereum Transaction Details (curl) Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/00-START-HERE.txt Example of fetching details for an Ethereum transaction using curl. Replace YOUR_KEY with your actual API key. ```bash curl "https://api.blockchair.com/ethereum/transaction/0x1a2b3c4d5e6f...1a2b3c4d5e6f?key=YOUR_KEY" ``` -------------------------------- ### Get Bitcoin Address Balance (curl) Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/00-START-HERE.txt Example of checking the balance of a Bitcoin address using curl. Replace YOUR_KEY with your actual API key. ```bash curl "https://api.blockchair.com/bitcoin/dash/address/1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa?key=YOUR_KEY" ``` -------------------------------- ### Get Bitcoin Transaction by Hash (curl) Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/00-START-HERE.txt Example of fetching a Bitcoin transaction by its hash using curl. Replace YOUR_KEY with your actual API key. ```bash curl "https://api.blockchair.com/bitcoin/transaction/a1b2c3d4e5f6...a1b2c3d4e5f6?key=YOUR_KEY" ``` -------------------------------- ### Get Bitcoin Block by Height (curl) Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/00-START-HERE.txt Example of fetching a Bitcoin block by its height using curl. Ensure you replace YOUR_KEY with your actual API key. ```bash curl "https://api.blockchair.com/bitcoin/block/1000000?key=YOUR_KEY" ``` -------------------------------- ### Basic API Request Source: https://github.com/blockchair/blockchair.support/blob/master/API_DOCUMENTATION_EN.md This section details how to make a basic GET request to the Blockchair API. It specifies the protocol, domain, and provides an example for fetching Bitcoin block data. ```APIDOC ## GET /bitcoin/blocks ### Description Fetches Bitcoin block data, with an example of summing generation. ### Method GET ### Endpoint `https://api.blockchair.com/bitcoin/blocks` ### Parameters #### Query Parameters - **a** (string) - Optional - Example: `sum(generation)` ### Request Example ```bash curl 'https://api.blockchair.com/bitcoin/blocks?a=sum(generation)' ``` ### Response #### Success Response (200) - **data** (array) - Contains the result of the query. - **sum(generation)** (integer) - The summed generation value. - **context** (object) - API context information. - **code** (integer) - HTTP status code. - **source** (string) - Data source identifier. - **time** (float) - Request processing time in seconds. - **limit** (integer) - Query limit. - **offset** (null) - Query offset. - **rows** (integer) - Number of rows returned. - **pre_rows** (integer) - Number of rows before the current set. - **total_rows** (integer) - Total number of rows available. - **state** (integer) - Internal state identifier. - **cache** (object) - Cache information. - **live** (boolean) - Indicates if the cache is live. - **duration** (integer) - Cache duration in minutes. - **since** (string) - Cache start time. - **until** (string) - Cache end time. - **time** (null) - Cache time. - **api** (object) - API information. - **version** (string) - API version. - **last_major_update** (string) - Timestamp of the last major update. - **next_major_update** (null) - Timestamp of the next major update. - **documentation** (string) - URL to the API documentation. - **notice** (string) - Important notice regarding API usage. #### Response Example ```json { "data": [ { "sum(generation)": 1800957104497237 } ], "context": { "code": 200, "source": "A", "time": 0.007825851440429688, "limit": 10000, "offset": null, "rows": 1, "pre_rows": 1, "total_rows": 1, "state": 600767, "cache": { "live": true, "duration": 60, "since": "2019-10-23 21:33:00", "until": "2019-10-23 21:34:00", "time": null }, "api": { "version": "2.0.38", "last_major_update": "2019-07-19 18:07:19", "next_major_update": null, "documentation": "https:\/\/github.com\/Blockchair\/Blockchair.Support\/blob\/master\/API.md", "notice": "Beginning July 19th, 2019 all applications using Blockchair API on a constant basis should apply for an API key (mailto:info@blockchair.com)" } } } ``` ``` -------------------------------- ### Get ERC-20 Token Transfers (curl) Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/00-START-HERE.txt Example of retrieving ERC-20 token transfers for a specific token contract address using curl. Replace YOUR_KEY with your actual API key. ```bash curl "https://api.blockchair.com/ethereum/erc-20/transfers?contract=0x...&key=YOUR_KEY" ``` -------------------------------- ### Use API Key in Requests (Python) Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/api-reference/usage-examples.md Demonstrates how to initialize a Blockchair API client with an API key and make authenticated requests. ```python import requests class BlockchairAPI: def __init__(self, api_key=None): self.api_key = api_key self.base_url = 'https://api.blockchair.com' def request(self, endpoint, **params): if self.api_key: params['key'] = self.api_key response = requests.get(f'{self.base_url}{endpoint}', params=params) data = response.json() if data['context']['code'] != 200: raise Exception(f"API Error: {data['context']['error']}") return data['data'] # Usage api = BlockchairAPI(api_key='your_api_key_here') stats = api.request('/bitcoin/stats') blocks = api.request('/bitcoin/blocks', q='time(~P1D)', a='count()') ``` -------------------------------- ### Fetch Bitcoin Address Balance (JavaScript) Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/00-START-HERE.txt JavaScript example to fetch the balance of a Bitcoin address. Requires the 'axios' library. Replace YOUR_KEY with your actual API key. ```javascript const axios = require('axios'); async function getAddressBalance(address) { try { const response = await axios.get(`https://api.blockchair.com/bitcoin/dash/address/${address}?key=YOUR_KEY`); console.log(`Balance for ${address}: ${response.data.data.address.balance}`); } catch (error) { console.error('Error fetching address balance:', error); } } getAddressBalance('1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa'); ``` -------------------------------- ### Get Latest Bitcoin Block Stats (Python) Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/api-reference/usage-examples.md Retrieve the latest block height and timestamp for the Bitcoin blockchain using the Python requests library. This example demonstrates parsing the JSON response. ```python import requests response = requests.get('https://api.blockchair.com/bitcoin/stats') data = response.json() print(f"Latest block: {data['context']['state']}") print(f"Block time: {data['data']['best_block_time']}") ``` -------------------------------- ### Get Bitcoin Transaction Count by Day Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/api-reference/usage-examples.md Retrieve the number of blocks created each day for the last 10 days on the Bitcoin blockchain. This Python example uses query parameters to filter and aggregate the data. ```bash curl 'https://api.blockchair.com/bitcoin/blocks?a=date,count()&limit=10' ``` ```python import requests response = requests.get( 'https://api.blockchair.com/bitcoin/blocks', params={ 'a': 'date,count()', 'limit': 10 } ) data = response.json() for row in data['data']: print(f"{row['date']}: {row['count()']} blocks") ``` -------------------------------- ### Infinitable Endpoints (SQL-like Queries) Source: https://github.com/blockchair/blockchair.support/blob/master/API_DOCUMENTATION_EN.md Retrieve data using SQL-like queries with options for filtering, sorting, and pagination. The example shows how to fetch transactions with a minimum USD value and handle pagination using the 'context.state' and 'offset' parameters. ```APIDOC ## Fetching Transactions with Minimum Value ### Description Retrieves the latest transactions from the Bitcoin blockchain with an amount greater than $1M USD. Demonstrates handling pagination by using the `context.state` and `offset` parameters. ### Method GET ### Endpoint `/bitcoin/transactions?q=output_total_usd(10000000..)&s=id(desc)` ### Query Parameters - **q** (string) - Required - Query filter. Example: `output_total_usd(10000000..)` - **s** (string) - Required - Sorting parameter. Example: `id(desc)` - **offset** (integer) - Optional - Used for pagination. Example: `10` ### Request Example `https://api.blockchair.com/bitcoin/transactions?q=output_total_usd(10000000..)&s=id(desc)` ### Response #### Success Response (200) Includes transaction data. The `context.state` field can be used for subsequent paginated requests. #### Response Example ```json { "data": { "bitcoin": { "transactions": [ { "id": 1234567, "output_total_usd": 1500000, "...other_fields...": "..." } ] } }, "context": { "state": "some_state_value" } } ``` ## Fetching Paginated Transactions ### Description Fetches subsequent pages of transactions by using the `offset` parameter and filtering by the `context.state` obtained from a previous request. ### Method GET ### Endpoint `/bitcoin/transactions?q=output_total_usd(10000000..),block_id(..{:state})&s=id(desc)&offset=10` ### Query Parameters - **q** (string) - Required - Query filter including the previous state. Example: `output_total_usd(10000000..),block_id(..{:state})` - **s** (string) - Required - Sorting parameter. Example: `id(desc)` - **offset** (integer) - Required - Offset for pagination. Example: `10` ### Request Example `https://api.blockchair.com/bitcoin/transactions?q=output_total_usd(10000000..),block_id(..{:state})&s=id(desc)&offset=10` ``` -------------------------------- ### Get Bitcoin Block Details by Height Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/api-reference/usage-examples.md Retrieve detailed information about a specific Bitcoin block using its height. This Python example shows how to access block hash, transaction count, size, and fee total. ```bash curl https://api.blockchair.com/bitcoin/dashboards/block/690164 ``` ```python import requests block_height = 690164 response = requests.get(f'https://api.blockchair.com/bitcoin/dashboards/block/{block_height}') data = response.json() block = data['data']['block'] print(f"Block Hash: {block['hash']}") print(f"Transactions: {block['tx_count']}") print(f"Size: {block['size']} bytes") print(f"Fee Total: {block['fee_total']} satoshi") ``` -------------------------------- ### API Key Authentication Examples Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/configuration.md Append your API key to requests using either '?' or '&' depending on existing parameters. Keep your API key secret and use a proxy server for client-side applications. ```bash # Using ? if no other parameters https://api.blockchair.com/bitcoin/stats?key=your_api_key ``` ```bash # Using & if other parameters exist https://api.blockchair.com/bitcoin/stats?limit=10&key=your_api_key ``` ```bash # Also valid https://api.blockchair.com/bitcoin/stats?key=your_api_key&limit=10 ``` ```bash User → https://your-proxy/{request} → https://api.blockchair.com/{request}?key={api_key} ``` -------------------------------- ### Get Largest Transactions (Last 24 Hours) Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/00-START-HERE.txt Retrieves the 10 largest Bitcoin transactions by input total within the last 24 hours. This example uses query parameters for time filtering, sorting, and limiting. ```bash curl 'https://api.blockchair.com/bitcoin/transactions?q=time(~P1D)&s=input_total(desc)&limit=10' ``` -------------------------------- ### Bitcoin Address Dashboard with Transaction Details Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/configuration.md Example for fetching address data including full transaction details and excluding unconfirmed transactions by setting 'state' to 'latest'. ```bash # Get address with full transaction details, excluding unconfirmed https://api.blockchair.com/bitcoin/dashboards/address/1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa?transaction_details=true&state=latest ``` -------------------------------- ### Get Daily Trading Volume (Last 30 Days) Source: https://github.com/blockchair/blockchair.support/blob/master/_autodocs/api-reference/usage-examples.md Fetches the daily trading volume for Bitcoin over the last 30 days, including date and sum of input totals. The Python example demonstrates how to convert satoshis to BTC. ```APIDOC ## Get Daily Trading Volume (Last 30 Days) ### Description Fetches the daily trading volume for Bitcoin over the last 30 days, including date and sum of input totals. The Python example demonstrates how to convert satoshis to BTC. ### Method GET ### Endpoint `/bitcoin/transactions` ### Query Parameters - **q** (string) - Required - Query filter, e.g., `time(~P30D)` - **a** (string) - Required - Aggregation, e.g., `date,sum(input_total)` - **s** (string) - Required - Sorting, e.g., `date(asc)` ### Request Example (Bash) ```bash curl 'https://api.blockchair.com/bitcoin/transactions?q=time(~P30D)&a=date,sum(input_total)&s=date(asc)' ``` ### Request Example (Python) ```python import requests response = requests.get( 'https://api.blockchair.com/bitcoin/transactions', params={ 'q': 'time(~P30D)', 'a': 'date,sum(input_total)', 's': 'date(asc)' } ) data = response.json() btc_unit = 100_000_000 # satoshi to BTC print("Date\t\tVolume (BTC)\tVolume (USD)") for day in data['data']: volume_btc = day['sum(input_total)'] / btc_unit # Would need current price for USD conversion print(f"{day['date']}\t{volume_btc:,.2f}") ``` ### Response #### Success Response (200) - **data** (object) - Contains daily trading volume data. - **date** (string) - The date of the trading volume. - **sum(input_total)** (number) - The total input volume for the day in satoshis. #### Response Example (JSON) ```json { "data": [ { "date": "2023-10-26", "sum(input_total)": 1234567890 } // ... more days ] } ``` ```