createSignerClient
Create a client with a bound signer for convenient repeated use.
The client provides signRequest, signedFetch, and fetch methods that automatically use the configured signer and default options.
Usage
Create a client by passing a signer and optional default configuration. The returned client exposes signRequest, signedFetch, and fetch methods.
import { createSignerClient } from '@slicekit/erc8128'
const client = createSignerClient(signer, {
ttlSeconds: 120,
replay: 'non-replayable',
})
// Use client.fetch (alias for signedFetch)
const response = await client.fetch('https://api.example.com/orders', {
method: 'POST',
body: JSON.stringify({ amount: '100' }),
})
// Override options per-call
const response = await client.fetch(
'https://api.example.com/status',
{ method: 'GET' },
{ replay: 'replayable' }
)
// Sign without sending
const signedRequest = await client.signRequest('https://api.example.com/orders')Returns
An object with bound methods:
signRequest— Sign a requestsignedFetch— Sign and send a requestfetch— Alias forsignedFetch
Parameters
signer
- Type:
EthHttpSigner
The signer to use for all requests.
defaults (optional)
- Type:
ClientOptions
Default options for all requests. Can be overridden per-call.
const client = createSignerClient(signer, {
ttlSeconds: 300,
replay: 'non-replayable',
fetch: customFetch,
})