signedFetch
Signs and sends an HTTP request in one call.
Internally, signedFetch uses signRequest to create the signed request, then sends it using fetch.
Usage
Call signedFetch with the same arguments as signRequest — it signs the request and sends it in a single step, returning the Response.
import { signedFetch } from '@slicekit/erc8128'
// Simple
const response = await signedFetch(
'https://api.example.com/orders',
signer
)
// With RequestInit
const response = await signedFetch(
'https://api.example.com/orders',
{ method: 'POST', body: JSON.stringify({ amount: '100' }) },
signer
)
// With options
const response = await signedFetch(
'https://api.example.com/orders',
{ method: 'POST', body: JSON.stringify({ amount: '100' }) },
signer,
{ ttlSeconds: 30 }
)
const data = await response.json()Returns
Promise<Response>
The fetch Response.
signedFetch signs only the request supplied by the caller, then delegates
redirect handling to the configured or native fetch. A followed redirect
never causes another wallet signature. The original signature remains scoped
to its original authority, method, and target; a redirected endpoint that
requires authentication must be signed explicitly in a separate call.
The signed request retains the caller's native redirect mode. As with normal
fetch, use redirect: 'manual' or redirect: 'error' when redirects must not
be followed.
Parameters
Overload 1: Simple
When no RequestInit is needed, pass the input and signer directly.
signedFetch(input: RequestInfo, signer: EthHttpSigner, opts?: SignOptions & { fetch?: typeof fetch }): Promise<Response>Overload 2: With RequestInit
When you need to specify method, headers, or body, pass a RequestInit as the second argument.
signedFetch(input: RequestInfo, init: RequestInit | undefined, signer: EthHttpSigner, opts?: SignOptions & { fetch?: typeof fetch }): Promise<Response>input
- Type:
RequestInfo
URL string or Request object.
init (optional)
- Type:
RequestInit | undefined
Optional RequestInit.
signer
- Type:
EthHttpSigner
The signer.
opts (optional)
- Type:
SignOptions& { fetch?: typeof fetch }
Sign options, plus an optional custom fetch implementation.
Examples
Custom Fetch
Provide a custom fetch implementation (useful for testing or edge runtimes):
const response = await signedFetch(
'https://api.example.com/orders',
{ method: 'POST', body: JSON.stringify({ amount: '100' }) },
signer,
{ fetch: customFetch }
)