Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
signedFetch – ERC-8128
Skip to content

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.

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

The signer.

opts (optional)

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 }
)