Create an x402-capable fetch for paid Glassnode calls (Node-first).
Dynamically loads the optional peer deps @x402/fetch + @x402/evm; pass the result as the
fetch option of GlassnodeAPI together with x402: true.
Errors:
Invalid maxPaymentPerCall → rejects with GlassnodeInputError (argument: 'maxPaymentPerCall').
Optional peer deps not installed → rejects with GlassnodeConfigError (import error on .cause).
The returned fetch rejects with a GlassnodePaymentError (surfaced as-is and never retried by
GlassnodeAPI) when:
the payment layer fails before a paid request is sent — e.g. the server's price is above
maxPaymentPerCall, the signer throws, or the 402 carries no usable payment requirements
(paymentMayHaveSettled: false: nothing was paid);
the call fails after a request carrying a signed payment was sent (paymentMayHaveSettled: true). The server may already have settled that payment and a retry would sign a new one,
so it is never retried. Either the paid request failed in transit (connection reset,
timeout abort: the transport error on .cause, timedOut set for a timeout), or it was
answered with a non-2xx status other than 402 — e.g. a proxy 502/504 after the origin
settled, a 429, a 400 — (status set, the equivalent GlassnodeApiError on .cause).
Redirects are never followed: the returned fetch passes redirect: 'manual' (a caller's
redirect: 'error' is kept; 'follow' is overridden), because fetch's default 'follow' resends
custom headers — the signed PAYMENT-SIGNATURE / X-PAYMENT — to whatever origin a 3xx names,
and a redirected unpaid request could be priced (and paid) by the redirect target. A 3xx to the
unpaid request is returned as-is (the client reports GlassnodeApiError with the 3xx status,
nothing signed); a 3xx to the paid request is a GlassnodePaymentError with status and
paymentMayHaveSettled: true, like any other non-2xx after payment.
A rejection of, or a non-2xx answer to, the unpaid request (no payment signed yet) is passed
through unchanged, so the client still reports and retries it (GlassnodeNetworkError, or
GlassnodeApiError for 429/5xx) when retries are enabled: in x402 mode maxRetries
defaults to 0, and an explicit value is safe with this fetch because only unpaid attempts are
ever retried. A 402 the server returns to the paid request (it
refused the payment) is not an error here either; the client reports it as GlassnodeApiError
(status 402), which it never retries.
Create an x402-capable
fetchfor paid Glassnode calls (Node-first).Dynamically loads the optional peer deps
@x402/fetch+@x402/evm; pass the result as thefetchoption ofGlassnodeAPItogether withx402: true.Errors:
maxPaymentPerCall→ rejects withGlassnodeInputError(argument: 'maxPaymentPerCall').GlassnodeConfigError(import error on.cause).The returned fetch rejects with a
GlassnodePaymentError(surfaced as-is and never retried byGlassnodeAPI) when:maxPaymentPerCall, the signer throws, or the402carries no usable payment requirements (paymentMayHaveSettled: false: nothing was paid);paymentMayHaveSettled: true). The server may already have settled that payment and a retry would sign a new one, so it is never retried. Either the paid request failed in transit (connection reset,timeoutabort: the transport error on.cause,timedOutset for a timeout), or it was answered with a non-2xx status other than402— e.g. a proxy502/504after the origin settled, a429, a400— (statusset, the equivalentGlassnodeApiErroron.cause).Redirects are never followed: the returned fetch passes
redirect: 'manual'(a caller'sredirect: 'error'is kept;'follow'is overridden), because fetch's default'follow'resends custom headers — the signedPAYMENT-SIGNATURE/X-PAYMENT— to whatever origin a 3xx names, and a redirected unpaid request could be priced (and paid) by the redirect target. A 3xx to the unpaid request is returned as-is (the client reportsGlassnodeApiErrorwith the 3xx status, nothing signed); a 3xx to the paid request is aGlassnodePaymentErrorwithstatusandpaymentMayHaveSettled: true, like any other non-2xx after payment.A rejection of, or a non-2xx answer to, the unpaid request (no payment signed yet) is passed through unchanged, so the client still reports and retries it (
GlassnodeNetworkError, orGlassnodeApiErrorfor429/5xx) when retries are enabled: inx402modemaxRetriesdefaults to 0, and an explicit value is safe with this fetch because only unpaid attempts are ever retried. A402the server returns to the paid request (it refused the payment) is not an error here either; the client reports it asGlassnodeApiError(status 402), which it never retries.