Skip to content

Providers

An instance of the Provider class lets you connect to a Fuel node. It provides read-only access to the blockchain state. You can use this provider as-is or through a Wallet instance.

ts
const provider = await Provider.create(FUEL_NETWORK_URL);
const { consensusParameters } = provider.getChain();
See code in context

You can also provide options to the Provider:

ts
await Provider.create(FUEL_NETWORK_URL, {
  fetch: async (url: string, requestInit: RequestInit | undefined) => {
    // do something
    await sleep(100);
    return fetch(url, requestInit);
  },
  timeout: 2000,
  cacheUtxo: 1500,
  requestMiddleware: async (request: RequestInit) => {
    const credentials = await fetchSomeExternalCredentials();
    request.headers ??= {};
    (request.headers as Record<string, string>).Authorization = credentials;

    return request;
  },
  retryOptions: {
    maxRetries: 5,
    baseDelay: 100,
    backoff: 'exponential',
  },
});
See code in context