@samooth/explorer

Cliente REST único para consultar explorers de BSV, BTC y Fractal Bitcoin.
Cambia de proveedor con una opción (api) sin cambiar el resto de tu código.
Contenidos
- Instalación
- Inicio rápido
- Endpoints soportados
- Opciones y límites
- API
- Desarrollo y tests
- Recursos
- Changelog
- Licencia
Instalación
npm install @samooth/explorer
Requiere Node >= 20.19.0.
Inicio rápido
import Explorer from '@samooth/explorer'
const explorer = new Explorer('main', { api: 'bananablocks' })
const chain = await explorer.chainInfo()
console.log(chain.chain, chain.blocks)
const utxos = await explorer.utxos('1Q5YLp6AxLFjFszFhBb4jCn4MQjGJXJjD4')
console.log(utxos.length)
También funciona con CommonJS en Node 20.19+/22.12+:
const Explorer = require('@samooth/explorer')
const explorer = new Explorer('main', { api: 'woc' })
La red puede ser main (alias: mainnet, livenet) o test (alias: testnet).
Endpoints soportados
| Coin |
api |
URL base |
Notas |
| BSV |
woc |
https://api.whatsonchain.com/v1/bsv/{main\|test}/ |
Default |
| BSV |
bitails |
https://api.bitails.io/ |
Con key usa subscription.bitails.io |
| BSV |
bsvdirect |
https://explora.bsv.direct/rest/ |
Cobertura parcial |
| BSV |
electrumx |
https://api.bsv.direct/e5/ |
Cobertura parcial |
| BSV |
bananablocks |
https://bananablocks.com/api/v1/bsv/main/ |
Mirror compatible con WoC |
| BTC |
mempoolSpace |
https://mempool.space/api/ |
|
| BTC |
woc |
https://api.whatsonchain.com/v1/btc/{main\|test}/ |
|
| FB |
mempoolSpace |
https://mempool.fractalbitcoin.io/ |
Fractal Bitcoin |
BananaBlocks usa su API compatible con WhatsOnChain: los métodos woc funcionan igual. En testnet la base es https://test.bananablocks.com/api/v1/bsv/test/. Los recibos PDF usan la ruta nativa download/tx/{txid}/receipt.
Puedes registrar endpoints propios:
const explorer = new Explorer('main')
explorer._endpoints.myAPI = {
main: 'https://my.api.tld/v1/',
test: 'https://my.api.tld/v1/test/',
headerKey: 'X-API-Key'
}
const custom = new Explorer('main', { api: 'myAPI' })
Opciones y límites
| Opción |
Default |
Descripción |
api |
woc |
Nombre del endpoint (ver tabla) |
coin |
BSV |
BSV, BTC o FB (insensible a mayúsculas) |
apiKey |
— |
Se envía en el header propio del endpoint |
timeout |
30000 |
Milisegundos |
userAgent |
— |
Header User-Agent |
cache |
true |
false desactiva cache y throttle |
threshold |
1000 / 200 |
ms entre peticiones (sin/con API key) |
url |
— |
Sobrescribe la URL base |
const explorer = new Explorer('main', {
api: 'woc',
apiKey: process.env.WOC_API_KEY,
timeout: 15000,
threshold: 1000,
cache: true
})
Límites de velocidad
- WhatsOnChain: 1 petición/s y 1 broadcast/s sin API key (cambios del 18 y 24/11/2026). Con key, de 5 a 20 peticiones/s según plan. El cliente aplica 1000 ms sin key y 200 ms con key; ajustable con
threshold.
- BananaBlocks: 240 req/min por IP y 10 broadcasts/min. La key (
bb_live_… / bb_test_…) es opcional y viaja en X-API-Key.
- Bitails: 3 req/s sin key.
Un método no soportado por el endpoint elegido rechaza con Not implemented (o devuelve undefined en algunos casos heredados). La matriz por método está en docs/API.md.
API
La clase expone métodos para chain, bloques, transacciones, mempool, direcciones y script hashes. Ejemplos rápidos:
await explorer.status()
await explorer.chainInfo()
await explorer.blockHash('00000000000000000be4e0ba7e7d96fa1901f59ec3898c6b352ec7cb1a45a981')
await explorer.txHash('4ad93a84ab3f461ce4e8da94ac10cf93693313ca7bc02df31d5d8ee8a6dd13d0', { format: 'hex' })
await explorer.broadcast(txHex)
await explorer.balance(address, { confirmed: true })
await explorer.history(address, { limit: 25 })
await explorer.utxos(address, { includeMempool: true })
await explorer.merkleProof(txid)
await explorer.search('texto')
- Referencia detallada y matriz de soporte: docs/API.md
- Cambios entre versiones: CHANGELOG.md
Desarrollo y tests
npm install
npm run build # vite build -> dist/explorer.mjs, dist/explorer.umd.js
npm test # build + 51 tests unitarios (node:test, sin red)
LIVE=1 npm test # +3 smoke tests contra BananaBlocks y WhatsOnChain
Detalles de la suite, estructura y cómo activar los tests en vivo: docs/TESTING.md.
Recursos
Changelog
La versión actual de trabajo es 0.3.15. Los cambios más recientes:
- BananaBlocks como endpoint compatible con WhatsOnChain (0.3.14).
- Throttle de 1 req/s para WhatsOnChain sin API key (0.3.14).
- Actualización de dependencias y suite de 54 tests (0.3.15).
Historial completo: CHANGELOG.md.
Licencia
MIT — Tomás Díaz (@samooth).