A comprehensive Clarity smart contract for indexing and querying blockchain data on the Stacks network. This contract provides a complete blockchain exploration solution with robust data management and query capabilities.
- Block Indexing: Store and retrieve complete block metadata
- Transaction Tracking: Index transactions with detailed information
- Address Analytics: Track address statistics and transaction history
- Bulk Operations: Efficient batch processing of multiple transactions
- Search Capabilities: Find blocks by miner and query ranges
- Owner-only administrative functions
- Contract activation/deactivation controls
- Comprehensive input validation
- Duplicate prevention mechanisms
- Proper error handling with descriptive error codes
{
block-hash: (buff 32),
timestamp: uint,
tx-count: uint,
miner: principal,
size: uint,
indexed-at: uint
}{
block-height: uint,
sender: principal,
recipient: (optional principal),
amount: uint,
fee: uint,
status: (string-ascii 20),
tx-type: (string-ascii 30)
}{
tx-count: uint,
total-sent: uint,
total-received: uint,
first-seen: uint,
last-active: uint
}index-block(height, hash, timestamp, tx-count, miner, size)- Index a new blockindex-transaction(tx-id, block-height, sender, recipient, amount, fee, status, tx-type)- Index a transactionbulk-index-transactions(tx-list)- Index up to 10 transactions in one calltoggle-contract-status()- Enable/disable contract functionality
get-block-info(height)- Get block information by heightget-transaction-info(tx-id)- Get transaction details by IDget-address-stats(addr)- Get address statisticsget-address-balance(addr)- Calculate address balanceget-block-range(start, end)- Get up to 10 blocks in rangesearch-blocks-by-miner(miner, start-height)- Find blocks mined by specific addressget-latest-block()- Get latest indexed block heightget-total-indexed-blocks()- Get total number of indexed blocksget-network-stats()- Get overall network statisticsget-contract-info()- Get contract metadata
| Code | Constant | Description |
|---|---|---|
| 100 | ERR-NOT-AUTHORIZED | Caller is not authorized |
| 101 | ERR-INVALID-BLOCK | Invalid block data |
| 102 | ERR-BLOCK-NOT-FOUND | Referenced block doesn't exist |
| 103 | ERR-INVALID-INPUT | Invalid input parameters |
| 104 | ERR-DATA-EXISTS | Data already exists |
MAX-BLOCKS: 1,000,000 (maximum blocks supported)MAX-TXS-PER-BLOCK: 100 (maximum transactions per block)
(contract-call? .blockchain-explorer index-block
u12345 ;; height
0x1234... ;; hash
u1640995200 ;; timestamp
u50 ;; tx-count
'SP1234... ;; miner
u1024) ;; size(contract-call? .blockchain-explorer get-block-info u12345)(contract-call? .blockchain-explorer get-address-stats 'SP1234...)(contract-call? .blockchain-explorer search-blocks-by-miner 'SP1234... u1000)- Network: Stacks blockchain
- Clarity Version: Compatible with Clarity 2.0+
- Contract Owner: Set during deployment (immutable)
- Bulk operations reduce transaction costs
- Limited query ranges prevent excessive gas usage
- Efficient data structures minimize storage costs
- Input validation prevents wasted computations
- Block range queries limited to 10 blocks per call
- Miner search returns up to 10 results per query
- Contract must be active for write operations
- Only contract owner can perform administrative functions
- All write functions require owner authorization
- Input validation prevents invalid data entry
- Contract can be deactivated in emergency situations
- No external dependencies reduce attack surface
- Code is optimized for readability and maintainability
- All functions include comprehensive error handling
- Uses only native Clarity functions for maximum compatibility
- Designed to handle high-volume blockchain data efficiently