clientFromNetwork
Returns the client configuration from a StacksNetwork object, ensuring a fetch function is always present. If the network's client.fetch is not set, a default fetch function is created automatically.
Usage
import { clientFromNetwork, STACKS_TESTNET } from '@stacks/network';
const client = clientFromNetwork(STACKS_TESTNET);
console.log(client.baseUrl); // 'https://api.testnet.hiro.so'
console.log(typeof client.fetch); // 'function' — always definedNotes
This is primarily used internally by
@stacks/transactionsnetworking functions to ensure a fetch function is always available.If
network.client.fetchis already set, it is returned as-is.If not set, a new default fetch function is created via
createFetchFn()from@stacks/common.
Signature
function clientFromNetwork(network: StacksNetwork): Required<ClientOpts>;Returns
Required<ClientOpts>
An object with both baseUrl and fetch guaranteed to be defined:
Parameters
network (required)
Type:
StacksNetwork
The network object to extract client configuration from.
Last updated
Was this helpful?