mempool.space API Reference
Complete API reference for mempool.space Bitcoin explorer. Addresses, transactions, blocks, fees, and mempool data.
mempool.space API Reference
mempool.space provides a free, open-source Bitcoin explorer API. It’s the recommended API for agents due to its reliability, comprehensive data, and no authentication requirements.
Base URLs
| Network | URL |
|---|---|
| Mainnet | https://mempool.space/api |
| Testnet | https://mempool.space/testnet/api |
| Signet | https://mempool.space/signet/api |
Rate Limits
- No API key required
- ~10 requests/second (soft limit)
- Consider running your own instance for high volume
Address Endpoints
Get Address Info
GET /address/{address}
Response:
{
"address": "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq",
"chain_stats": {
"funded_txo_count": 10,
"funded_txo_sum": 500000,
"spent_txo_count": 5,
"spent_txo_sum": 300000,
"tx_count": 15
},
"mempool_stats": {
"funded_txo_count": 0,
"funded_txo_sum": 0,
"spent_txo_count": 0,
"spent_txo_sum": 0,
"tx_count": 0
}
}
Get Address UTXOs
GET /address/{address}/utxo
Response:
[
{
"txid": "abc123...",
"vout": 0,
"status": {
"confirmed": true,
"block_height": 830000,
"block_hash": "000000000...",
"block_time": 1706745600
},
"value": 100000
}
]
Get Address Transactions
GET /address/{address}/txs
Returns up to 25 most recent transactions.
Pagination:
GET /address/{address}/txs/chain/{last_seen_txid}
Transaction Endpoints
Get Transaction
GET /tx/{txid}
Response:
{
"txid": "abc123...",
"version": 2,
"locktime": 0,
"vin": [{
"txid": "prev123...",
"vout": 0,
"prevout": {
"scriptpubkey": "0014...",
"scriptpubkey_address": "bc1q...",
"scriptpubkey_type": "v0_p2wpkh",
"value": 100000
},
"scriptsig": "",
"witness": ["304402...", "02a1b2..."],
"is_coinbase": false,
"sequence": 4294967293
}],
"vout": [{
"scriptpubkey": "0014...",
"scriptpubkey_address": "bc1q...",
"scriptpubkey_type": "v0_p2wpkh",
"value": 50000
}],
"size": 222,
"weight": 561,
"fee": 1000,
"status": {
"confirmed": true,
"block_height": 830000,
"block_hash": "000000000...",
"block_time": 1706745600
}
}
Get Transaction Status
GET /tx/{txid}/status
Response:
{
"confirmed": true,
"block_height": 830000,
"block_hash": "000000000...",
"block_time": 1706745600
}
Get Raw Transaction
GET /tx/{txid}/hex
Returns raw transaction hex string.
Broadcast Transaction
POST /tx
Content-Type: text/plain
{raw_tx_hex}
Success Response: Returns txid Error Response:
{
"error": "bad-txns-inputs-missingorspent"
}
Block Endpoints
Get Block
GET /block/{hash}
Get Block Height
GET /block-height/{height}
Returns block hash at given height.
Get Block Transactions
GET /block/{hash}/txs
GET /block/{hash}/txs/{start_index}
Returns 25 transactions per page.
Get Latest Block Height
GET /blocks/tip/height
Returns current blockchain height as integer.
Get Latest Block Hash
GET /blocks/tip/hash
Fee Endpoints
Recommended Fees
GET /v1/fees/recommended
Response:
{
"fastestFee": 45,
"halfHourFee": 35,
"hourFee": 25,
"economyFee": 15,
"minimumFee": 8
}
Fee Histogram
GET /v1/fees/mempool-blocks
Response:
[
{
"blockSize": 1500000,
"blockVSize": 1000000,
"nTx": 2500,
"totalFees": 25000000,
"medianFee": 25,
"feeRange": [15, 20, 25, 30, 45, 100]
}
]
Mempool Endpoints
Mempool Stats
GET /mempool
Response:
{
"count": 45000,
"vsize": 85000000,
"total_fee": 12500000000,
"fee_histogram": [
[25, 1500000],
[20, 3000000],
[15, 5000000]
]
}
Recent Mempool Transactions
GET /mempool/recent
Returns 10 most recent mempool entries.
Price Endpoints
Current Price
GET /v1/prices
Response:
{
"USD": 97500,
"EUR": 89000,
"GBP": 77000,
"time": 1706745600
}
Historical Price
GET /v1/historical-price?currency=USD×tamp={unix_timestamp}
WebSocket API
Real-time updates via WebSocket:
wss://mempool.space/api/v1/ws
Subscribe to Address
{"track-address": "bc1q..."}
Subscribe to Mempool
{"track-mempool": true}
Subscribe to Blocks
{"track-blocks": true}
Agent Code Examples
Check Address Balance
import requests
def get_balance(address):
url = f"https://mempool.space/api/address/{address}"
response = requests.get(url)
data = response.json()
confirmed = data['chain_stats']['funded_txo_sum'] - data['chain_stats']['spent_txo_sum']
unconfirmed = data['mempool_stats']['funded_txo_sum'] - data['mempool_stats']['spent_txo_sum']
return {
'confirmed': confirmed,
'unconfirmed': unconfirmed,
'total': confirmed + unconfirmed
}
Wait for Confirmation
import time
def wait_for_confirmation(txid, target_confirmations=1, timeout=3600):
start = time.time()
while time.time() - start < timeout:
response = requests.get(f"https://mempool.space/api/tx/{txid}/status")
status = response.json()
if status.get('confirmed'):
tip = requests.get("https://mempool.space/api/blocks/tip/height").text
confirmations = int(tip) - status['block_height'] + 1
if confirmations >= target_confirmations:
return {
'confirmed': True,
'confirmations': confirmations,
'block_height': status['block_height']
}
time.sleep(30) # Check every 30 seconds
return {'confirmed': False, 'timeout': True}
Broadcast Transaction
def broadcast_tx(tx_hex):
response = requests.post(
"https://mempool.space/api/tx",
data=tx_hex,
headers={'Content-Type': 'text/plain'}
)
if response.status_code == 200:
return {'success': True, 'txid': response.text}
else:
return {'success': False, 'error': response.text}
Get Optimal Fee
def get_fee_rate(priority='normal'):
response = requests.get("https://mempool.space/api/v1/fees/recommended")
fees = response.json()
priority_map = {
'urgent': 'fastestFee',
'normal': 'halfHourFee',
'economy': 'economyFee',
'minimum': 'minimumFee'
}
key = priority_map.get(priority, 'halfHourFee')
return fees[key]
Self-Hosting
For high-volume agents, run your own mempool.space instance:
git clone https://github.com/mempool/mempool
cd mempool
docker-compose up -d
Requires Bitcoin Core with txindex=1.
Machine-Readable Summary
{
"topic": "mempool-space-api",
"base_url": "https://mempool.space/api",
"authentication": "none",
"rate_limit": "~10/second",
"endpoints": {
"address": "/address/{address}",
"utxos": "/address/{address}/utxo",
"transaction": "/tx/{txid}",
"broadcast": "POST /tx",
"fees": "/v1/fees/recommended",
"mempool": "/mempool",
"price": "/v1/prices"
},
"websocket": "wss://mempool.space/api/v1/ws"
}