Client Configuration Options
Most of the client configuration is provided out-of-the-box from our Dashboard, and should not be changed in-hand. There are, however, a few additional configurations you can add to tweak the integration to your needs:
Property | Type | Default | Description |
---|---|---|---|
batchWindowMs | number | 25 | By default we batch requests in small windows to reduce unnecessary network overhead. If you have special needs, you can customize the window duration with this property. By providing a negative value (e.g. -1), you can disable request batching all together. In supported browsers batching happens with half-duplex connections, meaning that requests will be streamed to our infrastructure for instant processing in spite of batching. |
logLevel | string | warn | Configure the verbosity of outputs coming from the Direct Client, possible values are “debug”, “info”, “warn” and “error”. |
preferJSON | boolean | false | By default our client prefers communicating with Direct infrastructure using our custom-made Wire protocol. While the Wire format is heavily optimized and reduces bandwidth usage, the format is also not easily readable, and can make inspection and debugging difficult for developers. By enabling this setting, you can opt-in to using a NDJSON based format instead for a more developer-friendly transmission of data. Note that it is strongly discouraged to leave this setting on in production, as it negatively impacts the performance of your application as compared to using the Wire format. |
devMode | boolean | false | Puts the client into development mode, bypassing the Direct infrastructure for your end-users. When this setting is enabled, developers can opt into the full Direct integration by adding “?directdev=true” as a query parameter in the website URL. |
Example
Below is a basic example of applying these configurations in your provider:
Viem
// Import dependencies
import { createDirectViemClient } from "@direct.dev/viem";
// Initialize the Direct Client
const client = createDirectViemClient({
projectId: "your-project-id", // From the Direct dashboard
projectToken: "************", // From the Direct dashboard
networkId: "your-network-id", // e.g. "ethereum", "polygon"
providers: ["https://your-provider-endpoints.com/"],
// Additional options are added here
batchWindowMs: 50,
logLevel: "info",
preferJSON: true,
});
// Example: Fetch the latest block number
const blockNumber = await client.getBlockNumber();
Last updated on