Economic Query Client for BRC-178 race-settled collection markets: hosts compete to answer a query and the client pays the fastest that agree.
npm install @bsv/eqc @bsv/sdkimport { EQC } from '@bsv/eqc'
const eqc = new EQC(wallet)
const answer = await eqc.lookup({ service: 'ls_example', query: { key: 'value' } })import { createEconomicQueryHost, overlayLookupProvider } from '@bsv/eqc/host'
createEconomicQueryHost({ wallet, providers: [overlayLookupProvider({ engine })] }).mount(router)The host wallet internalizes payouts, so it needs a storage provider. On @bsv/overlay-express, do not pass the wallet a registerRouter factory receives: that is the BRC-103 authentication wallet, which has no storage provider and cannot create or internalize actions. Build a storage-backed wallet from the same root key as the node, so its identity equals the BRC-103 session key and the SLAP-advertised key:
const hostWallet = await buildStorageBackedWallet(serverPrivateKey)
server.registerRouter('/', ({ engine }) => {
const router = express.Router()
createEconomicQueryHost({
wallet: hostWallet,
providers: [overlayLookupProvider({ engine })]
}).mount(router)
return router
})buildStorageBackedWallet is a function the operator supplies.
EQC — discovers hosts from SLAP trackers, fans one BRC-103 authenticated query out to all of them, ranks BRC-77 attestations by local arrival time, pays the top K hosts that attested the same content hash from one square-root-weighted BRC-29 transaction, and returns bytes whose hash it verified.@bsv/eqc/host — GET /economic/params, POST /economic/query, and POST /economic/collect handlers with providers for overlay lookups, message box listings, and arbitrary byte reads.ls_slap lookup on the ordinary /lookup route names the hosts.threshold hosts attest one hash, the client pays the fastest topK of them. Below the threshold nobody is paid and no wallet call is made.A host that withholds data from its peers ends up alone with its hash and earns nothing. For overlay lookups, attestations carry BRC-136 topic anchors, and the result reports whether the winning hosts agree on the topic's confirmed history.
maxFeeSats per query, and hosts that take payment without delivering are excluded for ten minutes.AuthFetch (maxResponseBytes, default 16 MiB). SLAP advertisements name only canonical https, wss, or js8c+bsvauth+smf URIs, so plain http hosts under the local preset must be configured with hostOverrides, additionalHosts, or slapTrackers.threshold keys that agree on a fabricated answer. For reads that carry value, pin the hosts you trust with hostOverrides.getPublicKey, createSignature, verifySignature, createHmac, and verifyHmac.AuthFetch before this package can apply its 16 MiB cap, and cannot be cancelled. This is an @bsv/sdk limitation; maxHosts and hostTimeoutMs bound the exposure.i of k it requires floor(quotedFeeSats × weight(i) / S), so the enforceable minimum per delivery is max(minPayoutSats, share at rank K of K), not floorFeeSats. The advertised topK is the largest a host accepts.maxPayloadBytes (default 2 MiB). Keep it below the response limit of the server the routes are mounted on; the default fits the smallest @bsv/overlay-express profile (4 MiB).collectAttempts, default 3) and the host replays the same delivery without charging again, for deliveryRetentionMs after settlement (default ten minutes). A settle claim abandoned mid-settlement is taken over after settleLeaseMs, which internalizes the same payout again, so the host wallet must accept a transaction it already holds, as wallet-toolbox does. InMemoryPendingStore forgets everything on restart; replay across restarts needs a durable PendingStore.mount() rate-limits the three economic routes with express-rate-limit, 240 requests a minute per client by default (rateLimit option), counting by BRC-103 identity key or, before authentication, by address. Past the limit a route answers 429 ERR_RATE_LIMITED.txid, and the collect answers 500 rather than 402.pnpm doc: client entry and host entry