The unofficial Go SDK for the whatsonchain.com API supporting both BSV and BTC blockchains
| CIΒ /Β CD | QualityΒ &Β Security | DocsΒ &Β Meta | Community |
|---|---|---|---|
|
|
|
|
|
- Installation
- Usage
- Documentation
- Examples & Tests
- Benchmarks
- Code Standards
- AI Compliance
- Maintainers
- Contributing
- License
go-whatsonchain requires a supported release of Go.
go get github.com/mrz1836/go-whatsonchainpackage main
import (
"context"
"log"
"github.com/mrz1836/go-whatsonchain"
)
func main() {
// Create a client with default options (BSV mainnet)
client, err := whatsonchain.NewClient(context.Background())
if err != nil {
log.Fatal(err)
}
log.Println("client loaded", client.UserAgent())
log.Println("Chain:", client.Chain(), "Network:", client.Network())
}The library uses functional options for clean and flexible configuration:
package main
import (
"context"
"log"
"time"
"github.com/mrz1836/go-whatsonchain"
)
func main() {
// Create a client with custom options
client, err := whatsonchain.NewClient(
context.Background(),
whatsonchain.WithChain(whatsonchain.ChainBSV),
whatsonchain.WithNetwork(whatsonchain.NetworkMain),
whatsonchain.WithAPIKey("your-secret-key"),
whatsonchain.WithUserAgent("my-app/1.0"),
whatsonchain.WithRateLimit(10),
whatsonchain.WithRequestTimeout(60*time.Second),
whatsonchain.WithRequestRetryCount(3),
)
if err != nil {
log.Fatal(err)
}
log.Println("client loaded with custom options")
}WithChain(chain)- Set blockchain (ChainBSV or ChainBTC)WithNetwork(network)- Set network (NetworkMain, NetworkTest, NetworkStn)WithAPIKey(key)- Set API key for authenticated requestsWithUserAgent(agent)- Set custom user agentWithRateLimit(limit)- Set rate limit per secondWithHTTPClient(client)- Use custom HTTP clientWithRequestTimeout(timeout)- Set request timeoutWithRequestRetryCount(count)- Set retry count for failed requestsWithBackoff(initial, max, factor, jitter)- Configure exponential backoffWithDialer(keepAlive, timeout)- Configure dialer settingsWithTransport(idle, tls, expect, maxIdle)- Configure transport settings
package main
import (
"context"
"log"
"github.com/mrz1836/go-whatsonchain"
)
func main() {
// Create BSV client
client, err := whatsonchain.NewClient(
context.Background(),
whatsonchain.WithChain(whatsonchain.ChainBSV),
whatsonchain.WithNetwork(whatsonchain.NetworkMain),
)
if err != nil {
log.Fatal(err)
}
// Use BSV-specific methods
opReturnData, err := client.GetOpReturnData(context.Background(), "your-tx-hash")
if err != nil {
log.Fatal(err)
}
log.Println("OP_RETURN data:", opReturnData)
// Use shared methods (work for both BSV and BTC)
chainInfo, err := client.GetChainInfo(context.Background())
if err != nil {
log.Fatal(err)
}
log.Printf("BSV Chain Info: %+v", chainInfo)
}package main
import (
"context"
"log"
"github.com/mrz1836/go-whatsonchain"
)
func main() {
// Create BTC client
client, err := whatsonchain.NewClient(
context.Background(),
whatsonchain.WithChain(whatsonchain.ChainBTC),
whatsonchain.WithNetwork(whatsonchain.NetworkMain),
)
if err != nil {
log.Fatal(err)
}
// Use BTC-specific methods
blockStats, err := client.GetBlockStats(context.Background(), 700000)
if err != nil {
log.Fatal(err)
}
log.Printf("Block Stats: %+v", blockStats)
// Get miner statistics
minerStats, err := client.GetMinerBlocksStats(context.Background(), 7) // last 7 days
if err != nil {
log.Fatal(err)
}
log.Printf("Miner Stats: %+v", minerStats)
// Use shared methods (work for both BSV and BTC)
chainInfo, err := client.GetChainInfo(context.Background())
if err != nil {
log.Fatal(err)
}
log.Printf("BTC Chain Info: %+v", chainInfo)
}View the generated documentation
- Multi-blockchain support - Seamless switching between BSV and BTC blockchains with a single client
- Production-ready HTTP client - Built-in exponential backoff with configurable retry logic and crypto-secure jitter to handle transient failures gracefully
- Intelligent rate limiting - Per-second request throttling with automatic sleep intervals to stay within API quotas
- Zero external dependencies - Pure Go implementation with no production dependencies (testify only for testing)
- Comprehensive API coverage - 135+ endpoints (71 BSV, 64 BTC) fully implemented and tested
- Flexible configuration - Functional options pattern for clean, type-safe client initialization
- Enterprise-grade transport - Fine-grained control over timeouts, keep-alives, connection pooling, and TLS handshake settings
- Network flexibility - Switch between mainnet, testnet, and STN per client or per request
Heads up!
go-whatsonchainis intentionally light on dependencies. The only external package it uses is the excellenttestifysuiteβand that's just for our tests. You can drop this library into your projects without dragging along extra baggage.
Supported API Coverage
Coverage Summary: 135 total endpoints (71 BSV + 64 BTC) from the whatsonchain.com API
Quick Navigation: BSV API β’ BTC API β’ WebSockets
- Get Health Status -
/woc
- Get Blockchain Info -
/chain/info - Get Circulating Supply -
/circulatingsupply - Get Chain Tips -
/chain/tips - Get Peer Info -
/peer/info
- Get Block by Hash -
/block/hash/{hash} - Get Block by Height -
/block/height/{height} - Get Block Pages -
/block/hash/{hash}/page/{page} - Get Block Headers -
/block/headers - Get Header by Hash or Height -
/block/{hash}/header - Get Header Bytes File Links -
/block/headers/resources - Get Latest Header Bytes -
/block/headers/latest
- Get Transaction by Hash -
/tx/hash/{hash} - Get Transaction Propagation Status -
/tx/hash/{hash}/propagation - Broadcast Transaction -
/tx/raw(POST) - Bulk Transaction Details -
/txs(POST) - Bulk Transaction Status -
/txs/status(POST) - Decode Transaction -
/tx/decode(POST) - Download Receipt (PDF) - Receipt download
- Get Transaction as Binary -
/tx/{hash}/bin - Get Raw Transaction Data (Hex) -
/tx/{hash}/hex - Bulk Raw Transaction Data -
/txs/hex(POST) - Get Raw Transaction Output -
/tx/{hash}/out/{index}/hex - Bulk Raw Transaction Output Data -
/txs/vouts/hex(POST) - Get Merkle Proof (TSC) -
/tx/{hash}/proof/tsc
- Get Mempool Info -
/mempool/info - Get Mempool Transactions -
/mempool/raw
- Get Unspent UTXOs by Address -
/address/{address}/unspent/all - Get Unconfirmed UTXOs by Address -
/address/{address}/unconfirmed/unspent - Bulk Unconfirmed UTXOs by Address -
/addresses/unconfirmed/unspent(POST) - Get Confirmed UTXOs by Address -
/address/{address}/confirmed/unspent - Bulk Confirmed UTXOs by Address -
/addresses/confirmed/unspent(POST) - Get Unspent UTXOs by Script -
/script/{script}/unspent/all - Get Unconfirmed UTXOs by Script -
/script/{script}/unconfirmed/unspent - Bulk Unconfirmed UTXOs by Script -
/scripts/unconfirmed/unspent(POST) - Get Confirmed UTXOs by Script -
/script/{script}/confirmed/unspent - Bulk Confirmed UTXOs by Script -
/scripts/confirmed/unspent(POST) - Get Unconfirmed Spent Output -
/tx/{hash}/{index}/unconfirmed/spent - Get Confirmed Spent Output -
/tx/{hash}/{index}/confirmed/spent - Get Spent Transaction Output -
/tx/{hash}/{index}/spent - Bulk Spent Transaction Outputs -
/utxos/spent(POST)
- Get Address Info -
/address/{address}/info - Get Address Usage Status -
/address/{address}/used - Get Associated Scripthashes -
/address/{address}/scripts - Download Statement (PDF) - Statement download
- Get Unconfirmed Balance -
/address/{address}/unconfirmed/balance - Bulk Unconfirmed Balance -
/addresses/unconfirmed/balance(POST) - Get Confirmed Balance -
/address/{address}/confirmed/balance - Bulk Confirmed Balance -
/addresses/confirmed/balance(POST) - Get Unconfirmed History -
/address/{address}/unconfirmed/history - Bulk Unconfirmed History -
/addresses/unconfirmed/history(POST) - Get Confirmed History -
/address/{address}/confirmed/history - Bulk Confirmed History -
/addresses/confirmed/history(POST) - Bulk History (All) -
/addresses/history/all(POST)
- Get Script Usage Status -
/script/{script}/used - Get Unconfirmed Script History -
/script/{script}/unconfirmed/history - Bulk Unconfirmed Script History -
/scripts/unconfirmed/history(POST) - Get Confirmed Script History -
/script/{script}/confirmed/history - Bulk Confirmed Script History -
/scripts/confirmed/history(POST)
- Get Current Exchange Rate -
/exchangerate - Get Historical Exchange Rate -
/exchangerate/historical
- Get Explorer Links -
/search/links(POST)
- Get OP_RETURN Data -
/tx/{hash}/opreturn
- Get Block Stats by Height -
/block/height/{height}/stats - Get Block Stats by Hash -
/block/hash/{hash}/stats - Get Miner Block Stats -
/miner/blocks/stats - Get Miner Minimum Fee Rate Stats -
/miner/fees - Get Miner Summary Stats -
/miner/summary/stats - Get Tag Count by Height -
/block/tagcount/height/{height}/stats
- Get Token by Origin -
/token/1satordinals/{origin}/origin - Get Token by Outpoint -
/token/1satordinals/{outpoint} - Get Token Content -
/token/1satordinals/{outpoint}/content - Get Token Latest Transfer -
/token/1satordinals/{outpoint}/latest - Get Token Transfer History -
/token/1satordinals/{outpoint}/history - Get Tokens by TxID -
/token/1satordinals/tx/{txid} - Get 1Sat Ordinals Stats -
/tokens/1satordinals
- Get All STAS Tokens -
/tokens - Get STAS Token by ID -
/token/{contractId}/{symbol} - Get Token UTXOs for Address -
/address/{address}/tokens/unspent - Get Address Token Balance -
/address/{address}/tokens - Get Token Transactions -
/token/{contractId}/{symbol}/tx - Get STAS Stats -
/tokens/stas
- Get Health Status -
/woc
- Get Blockchain Info -
/chain/info - Get Circulating Supply -
/circulatingsupply - Get Chain Tips -
/chain/tips - Get Peer Info -
/peer/info
- Get Block by Hash -
/block/hash/{hash} - Get Block by Height -
/block/height/{height} - Get Block Pages -
/block/hash/{hash}/page/{page} - Get Block Headers -
/block/headers - Get Header by Hash or Height -
/block/{hash}/header - Get Header Bytes File Links -
/block/headers/resources - Get Latest Header Bytes -
/block/headers/latest
- Get Transaction by Hash -
/tx/hash/{hash} - Bulk Transaction Details -
/txs(POST) - Bulk Transaction Status -
/txs/status(POST) - Get Transaction as Binary -
/tx/{hash}/bin - Get Raw Transaction Data -
/tx/{hash}/hex - Bulk Raw Transaction Data -
/txs/hex(POST) - Get Raw Transaction Output -
/tx/{hash}/out/{index}/hex - Bulk Raw Transaction Output Data -
/txs/vouts/hex(POST) - Decode Transaction -
/tx/decode(POST)
- Get Mempool Info -
/mempool/info - Get Mempool Transactions -
/mempool/raw
- Get Unspent UTXOs by Address -
/address/{address}/unspent/all - Get Unconfirmed UTXOs by Address -
/address/{address}/unconfirmed/unspent - Bulk Unconfirmed UTXOs by Address -
/addresses/unconfirmed/unspent(POST) - Get Confirmed UTXOs by Address -
/address/{address}/confirmed/unspent - Bulk Confirmed UTXOs by Address -
/addresses/confirmed/unspent(POST) - Get Unspent UTXOs by Script -
/script/{script}/unspent/all - Get Unconfirmed UTXOs by Script -
/script/{script}/unconfirmed/unspent - Bulk Unconfirmed UTXOs by Script -
/scripts/unconfirmed/unspent(POST) - Get Confirmed UTXOs by Script -
/script/{script}/confirmed/unspent - Bulk Confirmed UTXOs by Script -
/scripts/confirmed/unspent(POST) - Get Unconfirmed Spent Output -
/tx/{hash}/{index}/unconfirmed/spent - Get Confirmed Spent Output -
/tx/{hash}/{index}/confirmed/spent - Get Spent Transaction Output -
/tx/{hash}/{index}/spent - Bulk Spent Transaction Outputs -
/utxos/spent(POST)
- Get Address Info -
/address/{address}/info - Get Address Usage Status -
/address/{address}/used - Get Associated Scripthashes -
/address/{address}/scripts - Get Unconfirmed Balance -
/address/{address}/unconfirmed/balance - Bulk Unconfirmed Balance -
/addresses/unconfirmed/balance(POST) - Get Confirmed Balance -
/address/{address}/confirmed/balance - Bulk Confirmed Balance -
/addresses/confirmed/balance(POST) - Get Unconfirmed History -
/address/{address}/unconfirmed/history - Bulk Unconfirmed History -
/addresses/unconfirmed/history(POST) - Get Confirmed History -
/address/{address}/confirmed/history - Bulk Confirmed History -
/addresses/confirmed/history(POST) - Bulk History (All) -
/addresses/history/all(POST)
- Get Script Usage Status -
/script/{script}/used - Get Unconfirmed Script History -
/script/{script}/unconfirmed/history - Bulk Unconfirmed Script History -
/scripts/unconfirmed/history(POST) - Get Confirmed Script History -
/script/{script}/confirmed/history - Bulk Confirmed Script History -
/scripts/confirmed/history(POST)
- Get Current Exchange Rate -
/exchangerate - Get Historical Exchange Rate -
/exchangerate/historical
- Get Explorer Links -
/search/links(POST)
- Get Block Stats by Height -
/block/height/{height}/stats - Get Block Stats by Hash -
/block/hash/{hash}/stats - Get Miner Block Stats -
/miner/blocks/stats - Get Miner Minimum Fee Rate Stats -
/miner/fees - Get Miner Summary Stats -
/miner/summary/stats - Get Tag Count by Height -
/block/tagcount/height/{height}/stats
Development Setup (Getting Started)
Install MAGE-X build tool for development:
# Install MAGE-X for development and building
go install github.com/mrz1836/mage-x/cmd/magex@latest
magex update:installLibrary Deployment
This project uses goreleaser for streamlined binary and library deployment to GitHub. To get started, install it via:
brew install goreleaserThe release process is defined in the .goreleaser.yml configuration file.
Then create and push a new Git tag using:
magex version:bump push=true bump=patch branch=masterThis process ensures consistent, repeatable releases with properly versioned artifacts and citation metadata.
Build Commands
View all build commands
magex helpGitHub Workflows
All GitHub Actions workflows in this repository are powered by configuration files: .env.base (default configuration) and optionally .env.custom (project-specific overrides) β your one-stop shop for tweaking CI/CD behavior without touching a single YAML file! π―
Configuration Files:
- .env.base β Default configuration that works for most Go projects
- .env.custom β Optional project-specific overrides
This magical file controls everything from:
- π Go version matrix (test on multiple versions or just one)
- π Runner selection (Ubuntu or macOS, your wallet decides)
- π¬ Feature toggles (coverage, fuzzing, linting, race detection, benchmarks)
- π‘οΈ Security tool versions (gitleaks, nancy, govulncheck)
- π€ Auto-merge behaviors (how aggressive should the bots be?)
- π·οΈ PR management rules (size labels, auto-assignment, welcome messages)
Pro tip: Want to disable code coverage? Just add
ENABLE_CODE_COVERAGE=falseto your .env.custom to override the default in .env.base and push. No YAML archaeology required!
| Workflow Name | Description |
|---|---|
| auto-merge-on-approval.yml | Automatically merges PRs after approval and all required checks, following strict rules. |
| codeql-analysis.yml | Analyzes code for security vulnerabilities using GitHub CodeQL. |
| dependabot-auto-merge.yml | Automatically merges Dependabot PRs that meet all requirements. |
| fortress.yml | Runs the GoFortress security and testing workflow, including linting, testing, releasing, and vulnerability checks. |
| pull-request-management.yml | Labels PRs by branch prefix, assigns a default user if none is assigned, and welcomes new contributors with a comment. |
| scorecard.yml | Runs OpenSSF Scorecard to assess supply chain security. |
| stale.yml | Warns about (and optionally closes) inactive issues and PRs on a schedule or manual trigger. |
| sync-labels.yml | Keeps GitHub labels in sync with the declarative manifest at .github/labels.yml. |
Updating Dependencies
To update all dependencies (Go modules, linters, and related tools), run:
magex deps:updateThis command ensures all dependencies are brought up to date in a single step, including Go modules and any managed tools. It is the recommended way to keep your development environment and CI in sync with the latest versions.
All unit tests and fuzz tests run via GitHub Actions and use Go version 1.24.x. View the configuration file.
Run all tests (fast):
magex testRun all tests with race detector (slower):
magex test:raceRun the Go benchmarks:
magex bench time=2sBenchmarks run on Apple M1 Max using Go's built-in benchmark tool with 2-second intervals.
| Operation | Time (ns/op) | Memory (B/op) | Allocations (allocs/op) |
|---|---|---|---|
| Client Operations | |||
| Client Creation (Minimal) | 275 | 1,048 | 9 |
| Client Creation (Fully Configured) | 287 | 1,048 | 9 |
| Build URL (Simple) | 158 | 144 | 4 |
| Build URL (With Args) | 194 | 168 | 5 |
| Get Chain Config | 2.1 | 0 | 0 |
| Set Chain Config | 2.1 | 0 | 0 |
| Address Operations | |||
| Get Address Info | 2,748 | 2,697 | 25 |
| Get Address Balance | 2,209 | 2,393 | 24 |
| Get Address History | 3,605 | 3,097 | 32 |
| Get Address UTXOs | 5,668 | 3,705 | 36 |
| Get Confirmed Balance | 2,391 | 2,337 | 22 |
| Get Unconfirmed Balance | 2,683 | 2,337 | 22 |
| Transaction Operations | |||
| Get Transaction by Hash | 8,117 | 6,035 | 43 |
| Bulk Transaction Details (1 tx) | 15,536 | 14,135 | 69 |
| Bulk Transaction Details (20 txs) | 17,489 | 16,815 | 69 |
| Broadcast Transaction | 2,071 | 2,753 | 26 |
| Decode Transaction | 9,294 | 6,835 | 54 |
| Get Merkle Proof | 5,679 | 3,826 | 40 |
| Get Spent Output | 4,431 | 3,233 | 31 |
| Block Operations | |||
| Get Block by Hash | 11,271 | 6,307 | 48 |
| Get Block by Height | 8,691 | 5,963 | 47 |
| Get Block Pages | 3,104 | 2,833 | 30 |
| Get Header by Hash | 10,296 | 6,435 | 49 |
| Get Latest Header Bytes | 2,109 | 3,905 | 21 |
| Chain Info Operations | |||
| Get Chain Info | 3,442 | 2,881 | 24 |
| Get Chain Tips | 2,546 | 2,497 | 27 |
| Get Circulating Supply | 1,514 | 1,993 | 17 |
| Get Exchange Rate | 2,569 | 2,433 | 26 |
| Get Historical Exchange Rate | 3,916 | 3,089 | 36 |
| Get Peer Info | 6,467 | 3,641 | 33 |
| Get Mempool Info | 3,068 | 2,633 | 27 |
| Get Mempool Transactions | 2,648 | 2,593 | 32 |
Notes:
- All times are in nanoseconds per operation
- Memory is bytes allocated per operation
- Benchmarks use mock HTTP responses for consistent, reproducible results
To reproduce these benchmarks:
magex bench time=2sRead more about this Go project's code standards.
This project documents expectations for AI assistants using a few dedicated files:
- AGENTS.md β canonical rules for coding style, workflows, and pull requests used by Codex.
- CLAUDE.md β quick checklist for the Claude agent.
- .cursorrules β machine-readable subset of the policies for Cursor and similar tools.
- sweep.yaml β rules for Sweep, a tool for code review and pull request management.
Edit AGENTS.md first when adjusting these policies, and keep the other files in sync within the same pull request.
![]() |
|---|
| MrZ |
View the contributing guidelines and please follow the code of conduct.
All kinds of contributions are welcome π! The most basic way to show your support is to star π the project, or to raise issues π¬. You can also support this project by becoming a sponsor on GitHub π or by making a bitcoin donation to ensure this journey continues indefinitely! π
