Skip to content

Commit

Permalink
docs: add docs around provider options
Browse files Browse the repository at this point in the history
  • Loading branch information
nedsalk committed Mar 5, 2024
1 parent 68599df commit 10d7176
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
32 changes: 32 additions & 0 deletions apps/docs-snippets/src/guide/provider/provider.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { FUEL_NETWORK_URL, Provider, sleep } from 'fuels';

async function fetchSomeExternalCredentials() {
return Promise.resolve('credential');
}
describe('Provider', () => {
it('can be given options', async () => {
// #region provider-options
await Provider.create(FUEL_NETWORK_URL, {
fetch: async (url, requestInit) => {
// do something
await sleep(100);
return fetch(url, requestInit);
},
timeout: 2000,
cacheUtxo: 1500,
requestMiddleware: async (request) => {
const credentials = await fetchSomeExternalCredentials();
request.headers ??= {};
(request.headers as Record<string, string>).Authorization = credentials;

return request;
},
retryOptions: {
maxRetries: 5,
baseDelay: 100,
backoff: 'exponential',
},
});
// #endregion provider-options
});
});
4 changes: 4 additions & 0 deletions apps/docs/src/guide/providers/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
An instance of the [`Provider`](../../api/Account/Provider.md) 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`](../../api/Account/Wallet.md) instance.

<<< @/../../../packages/account/src/providers/provider.test.ts#provider-definition{ts:line-numbers}

You can also provide options to the `Provider`:

<<< @/../../docs-snippets/src/guide/provider/provider.test.ts#provider-options{ts:line-numbers}

0 comments on commit 10d7176

Please sign in to comment.